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

com.aliyun.EdasDeployMojo 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.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

@Mojo( name = "deploy", defaultPhase = LifecyclePhase.PACKAGE)
public class EdasDeployMojo extends AbstractMojo {

    @Parameter(readonly = true, defaultValue = "${project}")
    private MavenProject project;

    @Parameter(property = "edas_config")
    private String configFile;

    @Parameter(property = "access_key_id")
    private String accessKeyId;

    @Parameter(property = "access_key_secret")
    private String accessKeySecret;

    @Parameter(property = "access_key_file")
    private String accessKeyFile;

    private DefaultConfigBean config;

    private LoadConfigManager loadConfigManager;
    private UploadPackageManager uploadPackageManager;
    private DeployPackageManager deployPackageManager;
    private ChangeOrderManager changeOrderManager;
    private ReportManager reportManager;

    private DefaultAcsClient defaultAcsClient;

    public void execute() throws MojoExecutionException {
        loadProperties();
        init();
        uploadPackage();
        String changeOrderId = deployPackage();
        traceChangeOrder(changeOrderId);
        report(true);
    }

    private void report(boolean success) {
        reportManager.report(config, success);
    }

    private void init() throws MojoExecutionException {
        Log logger = getLog();
        CommonUtils.initLogger(logger);
        uploadPackageManager = new UploadPackageManager(project, logger);
        deployPackageManager = new DeployPackageManager(logger);
        changeOrderManager = new ChangeOrderManager(config, logger);
        reportManager = new ReportManager(logger);

        try {
            DefaultConfigBean.Env env = config.getEnv();
            DefaultProfile.addEndpoint(env.getRegionId(), env.getRegionId(), "Edas", env.getDomain());
            DefaultProfile defaultProfile = DefaultProfile.getProfile(env.getRegionId(),
                    env.getAccessKeyId(), env.getAccessKeySecret());
            defaultAcsClient = new DefaultAcsClient(defaultProfile);
            defaultAcsClient.setAutoRetry(false);
        } catch (Exception ex) {
            String msg = "Init EDAS sdk client failed.";
            logger.error(msg, ex);
            throw new MojoExecutionException(msg);
        }

    }

    private void uploadPackage() throws MojoExecutionException {
        if ("url".equals(config.getApp().getDeployType())
                && config.getApp().getWarUrl() != null) {
            return;
        }

        String warUrl = uploadPackageManager.uploadPackage(config);
        config.getApp().setWarUrl(warUrl);
    }

    private String deployPackage() throws MojoExecutionException {
        return deployPackageManager.deployPackage(defaultAcsClient, config);
    }

    private void traceChangeOrder(String changeOrderId) throws MojoExecutionException {
        changeOrderManager.trace(defaultAcsClient, changeOrderId);
    }

    private void loadProperties() throws MojoExecutionException {
        loadConfigManager = new LoadConfigManager(project, getLog());
        config = loadConfigManager.loadProperties(configFile, accessKeyFile, accessKeyId, accessKeySecret);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy