All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.DeployPackageManager Maven / Gradle / Ivy

Go to download

Aliyun Open API SDK for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 1.1.9
Show newest version
package com.aliyun;

import com.aliyun.bean.DefaultConfigBean;
import com.aliyun.enums.Constants;
import com.aliyun.utils.PluginUtils;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.edas.model.v20170801.DeployApplicationRequest;
import com.aliyuncs.edas.model.v20170801.DeployApplicationResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;

import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

public class DeployPackageManager {
    private Log logger;

    public DeployPackageManager(Log logger) {
        this.logger = logger;
    }

    public String deployPackage(DefaultAcsClient defaultAcsClient,
            DefaultConfigBean config) throws MojoExecutionException {
        DefaultConfigBean.App app = config.getApp();
        try {
            //init request
            DeployApplicationRequest request = new DeployApplicationRequest();
            request.putHeaderParameter(Constants.DEPLOY_SOURCE_HEADER_KEY, PluginUtils.getVersion());
            String routeKey = CommonUtils.getPopApiRouteKey();
            if (routeKey != null) {
                request.putHeaderParameter(Constants.POP_API_ROUTE_KEY, routeKey);
            }
            request.setAppId(app.getAppId());
            request.setGroupId(app.getGroupId());
            request.setDeployType(app.getDeployType());

            if ("url".equals(app.getDeployType())) {
                request.setWarUrl(app.getWarUrl());
            } else if ("image".equals(app.getDeployType())) {
                request.setImageUrl(app.getImageUrl());
            }

            if (app.getBatch() != null) {
                request.setBatch(app.getBatch());
            }
            if (app.getBatchWaitTime() != null) {
                request.setBatchWaitTime(app.getBatchWaitTime());
            }
            if (app.getPackageVersion() != null) {
                request.setPackageVersion(app.getPackageVersion());
            } else {
                request.setPackageVersion(CommonUtils.getCurrentTime());
            }
            if (app.getDesc() != null) {
                request.setDesc(app.getDesc());
            }
            //send request
            logger.info("Sending deploy request to EDAS...");
            DeployApplicationResponse response = defaultAcsClient.getAcsResponse(request);
            if (response.getCode() == 200) {
                String changeOrderId = response.getChangeOrderId();
                logger.info("Deploy request sent, changeOrderId is: " + changeOrderId);
                return changeOrderId;
            } else {
                String msg = "Failed to send deploy request: " + response.getMessage();
                logger.error(msg);
                throw new MojoExecutionException(msg);
            }

        } catch (ClientException ex) {
            String msg = "Failed to send deploy request: " + ex.getMessage();
            logger.error(msg, ex);
            throw new MojoExecutionException(msg);
        }

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy