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

com.aliyun.manager.AppManager Maven / Gradle / Ivy

package com.aliyun.manager;

import com.aliyun.Context;
import com.aliyun.bean.config.DefaultConfigBean;
import com.aliyun.enums.Constants;
import com.aliyun.utils.CommonUtils;
import com.aliyuncs.DefaultAcsClient;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;

public class AppManager {
    /*
    private Log logger;
    private AppConfigManager appConfigManager;
    private UploadPackageManager uploadPackageManager;
    private ImageManager imageManager;
    private DeployPackageManager deployPackageManager;
    private ChangeOrderManager changeOrderManager;
    private ReportManager reportManager = new ReportManager();

    public AppManager(MavenProject project) {
        logger = Context.getLogger();
        appConfigManager = new AppConfigManager();
        uploadPackageManager = new UploadPackageManager(project);
        imageManager = new ImageManager();
        deployPackageManager = new DeployPackageManager();
        changeOrderManager = new ChangeOrderManager();
        reportManager = new ReportManager();
    }

    public void process(DefaultConfigBean config, MavenProject project, DefaultAcsClient defaultAcsClient) throws Exception {
        logger.info("Processing app config...");
        completeAppConfig(config, project, defaultAcsClient);
        uploadPackage(config);
        buildAndUploadImage(config, project);
        String changeOrderId = deployPackage(config, defaultAcsClient);
        traceChangeOrder(config, defaultAcsClient, changeOrderId);
        report(config, true);
    }

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

    private void traceChangeOrder(
            DefaultConfigBean config, DefaultAcsClient defaultAcsClient,
            String changeOrderId) throws Exception {
        changeOrderManager.trace(
                defaultAcsClient, changeOrderId,
                config.getApp().getServiceStageTimeout(),
                config.getApp().getInstanceStageTimeout());
    }

    private String deployPackage(DefaultConfigBean config, DefaultAcsClient defaultAcsClient) throws Exception {
        return deployPackageManager.deployPackage(defaultAcsClient, config);
    }

    private void buildAndUploadImage(DefaultConfigBean config, MavenProject project) throws Exception {
        if (!Constants.SERVERLESS.equals(config.getApp().getClusterType())) {
            return;
        }

        if (!Constants.IMAGE.equalsIgnoreCase(config.getApp().getPackageType())) {
            return;
        }

        if (config.getApp().getImageUrl() != null) {
            logger.info("Image url is set, skip building image.");
            return;
        }

        if (config.getApp().getImageRepoAddress() == null) {
            throw new Exception("Failed to build image: image_repo_address is not set");
        }

        if (config.getApp().getImageTag() == null) {
            throw new Exception("Failed to build image: image_tag is not set");
        }

        DefaultConfigBean.App app = config.getApp();
        String dockerfile = app.getDockerfile();
        if (dockerfile == null) {
            dockerfile = Constants.DOCKERFILE;
        }
        logger.info(String.format(
                "Use %s to build image in current build repository(%s)",
                dockerfile, project.getBasedir().getPath()));
        imageManager.buildAndUploadImage(
                dockerfile, app.getImageRepoAddress(), app.getImageTag(),
                app.getImageRepoUser(), app.getImageRepoPassword(), project);
    }

    private void completeAppConfig(
            DefaultConfigBean config, MavenProject project, DefaultAcsClient defaultAcsClient) throws Exception {
        appConfigManager.complete(config, project, defaultAcsClient);
    }

    private void uploadPackage(DefaultConfigBean config) throws Exception {
        boolean isServerless = Constants.SERVERLESS.equals(config.getApp().getClusterType());
        if (isServerless) {
            if (Constants.IMAGE.equalsIgnoreCase(config.getApp().getPackageType())) {
                return;
            }
            if (config.getApp().getPackageUrl() != null) {
                return;
            }
        } else {
            if (Constants.URL.equals(config.getApp().getDeployType())
                    && config.getApp().getWarUrl() != null) {
                return;
            }
        }

        DefaultConfigBean.App app = config.getApp();
        DefaultConfigBean.Oss oss = config.getOss();
        String endpoint = config.getEnv().getEndpoint();
        String regionId = config.getEnv().getRegionId();
        String edasAK = config.getEnv().getAccessKeyId();
        String edasSK = config.getEnv().getAccessKeySecret();
        String appId = config.getApp().getAppId();
        String packageVersion = config.getApp().getPackageVersion();
        if (packageVersion == null) {
            //TODO 在更早前设置此值
            packageVersion = CommonUtils.getCurrentTime();
        }
        String downloadUrl = uploadPackageManager.uploadPackage(endpoint, regionId, edasAK, edasSK, appId, packageVersion, oss);

        if (isServerless) {
            config.getApp().setPackageUrl(downloadUrl);
        } else {
            config.getApp().setWarUrl(downloadUrl);
        }
    }
    */
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy