Search in sources :

Example 6 with CarbonApplication

use of org.wso2.carbon.application.deployer.CarbonApplication in project carbon-business-process by wso2.

the class BPMNAppDeployer method deployArtifacts.

/**
 * Check the artifact type and if it is a BPMN artifact, copy it to the BPMN deployment hot folder
 *
 * @param carbonApp  - CarbonApplication instance to check for BPMN artifacts
 * @param axisConfig - AxisConfiguration of the current tenant
 */
public void deployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) throws DeploymentException {
    List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
    // loop through all dependencies
    for (Artifact.Dependency dep : artifacts) {
        Deployer deployer;
        Artifact artifact = dep.getArtifact();
        if (artifact == null) {
            continue;
        }
        if (!isAccepted(artifact.getType())) {
            log.warn("Can't deploy artifact : " + artifact.getName() + " of type : " + artifact.getType() + ". Required features are not installed in the system");
            continue;
        }
        if (BPMN_TYPE.equals(artifact.getType())) {
            deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, BPMN_DIR, "bar");
        } else {
            continue;
        }
        List<CappFile> files = artifact.getFiles();
        if (files.size() != 1) {
            log.error("BPMN artifacts must have a single file to " + "be deployed. But " + files.size() + " files found.");
            continue;
        }
        if (deployer != null) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            try {
                deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                File artifactFile = new File(artifactPath);
                if (artifactFile.exists() && !artifactFile.delete()) {
                    log.warn("Couldn't delete App artifact file : " + artifactPath);
                }
            } catch (DeploymentException e) {
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                throw e;
            }
        }
    }
}
Also used : DeploymentFileData(org.apache.axis2.deployment.repository.util.DeploymentFileData) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File) CappFile(org.wso2.carbon.application.deployer.config.CappFile) Artifact(org.wso2.carbon.application.deployer.config.Artifact) Deployer(org.apache.axis2.deployment.Deployer) CappFile(org.wso2.carbon.application.deployer.config.CappFile)

Example 7 with CarbonApplication

use of org.wso2.carbon.application.deployer.CarbonApplication in project carbon-business-process by wso2.

the class HumanTaskApplicationAdmin method getHumanTaskAppData.

/**
 * Gives a HumanTaskAppMetadata object with all humantask packages deployed through the
 * given app.
 *
 * @param appName - input app name
 * @return - HumanTaskAppMetadata object with found artifact info
 * @throws Exception - error on retrieving metadata
 */
public HumanTaskAppMetadata getHumanTaskAppData(String appName) throws Exception {
    HumanTaskAppMetadata data = new HumanTaskAppMetadata();
    String tenantId = AppDeployerUtils.getTenantIdString(getAxisConfig());
    // Check whether there is an application in the system from the given name
    ArrayList<CarbonApplication> appList = HumanTaskAppMgtServiceComponent.getAppManager().getCarbonApps(tenantId);
    CarbonApplication currentApplication = null;
    for (CarbonApplication application : appList) {
        if (appName.equals(application.getAppNameWithVersion())) {
            currentApplication = application;
            break;
        }
    }
    // If the app not found, throw an exception
    if (currentApplication == null) {
        String msg = "No Carbon Application found of the name : " + appName;
        log.error(msg);
        throw new Exception(msg);
    }
    // get all dependent artifacts of the cApp
    List<Artifact.Dependency> deps = currentApplication.getAppConfig().getApplicationArtifact().getDependencies();
    // we use the humantask backend admin service to get tasks from a humantask package
    HumanTaskPackageManagementSkeleton humantaskAdmin = new HumanTaskPackageManagementSkeleton();
    // package list to return
    List<PackageMetadata> packageList = new ArrayList<PackageMetadata>();
    String packageName;
    for (Artifact.Dependency dep : deps) {
        Artifact artifact = dep.getArtifact();
        packageName = artifact.getRuntimeObjectName();
        if (packageName == null) {
            continue;
        }
        if (HumanTaskAppDeployer.HUMANTASK_TYPE.equals(artifact.getType())) {
            PackageMetadata packageMetadata = new PackageMetadata();
            packageMetadata.setPackageName(packageName);
            // get the list of tasks
            List<String> taskList = new ArrayList<String>();
            Task_type0[] tasksInPackage = humantaskAdmin.listTasksInPackage(packageName);
            for (Task_type0 taskInfo : tasksInPackage) {
                taskList.add(taskInfo.getName());
            }
            String[] tasks = new String[taskList.size()];
            packageMetadata.setTaskList(tasks);
            packageList.add(packageMetadata);
        }
    }
    // convert the List into an array
    data.setPackages(packageList.toArray(new PackageMetadata[packageList.size()]));
    return data;
}
Also used : ArrayList(java.util.ArrayList) CarbonApplication(org.wso2.carbon.application.deployer.CarbonApplication) Artifact(org.wso2.carbon.application.deployer.config.Artifact) HumanTaskPackageManagementSkeleton(org.wso2.carbon.humantask.skeleton.mgt.services.HumanTaskPackageManagementSkeleton) Task_type0(org.wso2.carbon.humantask.skeleton.mgt.services.types.Task_type0)

Example 8 with CarbonApplication

use of org.wso2.carbon.application.deployer.CarbonApplication in project carbon-business-process by wso2.

the class BPELApplicationAdmin method getBPELAppData.

/**
 * Gives a BPELAppMetadata object with all bpel packages deployed through the
 * given app.
 *
 * @param appName - input app name
 * @return - BPELAppMetadata object with found artifact info
 * @throws Exception - error on retrieving metadata
 */
public BPELAppMetadata getBPELAppData(String appName) throws Exception {
    BPELAppMetadata data = new BPELAppMetadata();
    String tenantId = AppDeployerUtils.getTenantIdString(getAxisConfig());
    // Check whether there is an application in the system from the given name
    ArrayList<CarbonApplication> appList = BPELAppMgtServiceComponent.getAppManager().getCarbonApps(tenantId);
    CarbonApplication currentApplication = null;
    for (CarbonApplication application : appList) {
        if (appName.equals(application.getAppNameWithVersion())) {
            currentApplication = application;
            break;
        }
    }
    // If the app not found, throw an exception
    if (currentApplication == null) {
        String msg = "No Carbon Application found of the name : " + appName;
        log.error(msg);
        throw new Exception(msg);
    }
    // get all dependent artifacts of the cApp
    List<Artifact.Dependency> deps = currentApplication.getAppConfig().getApplicationArtifact().getDependencies();
    // we use the bpel backend admin service to get processes from a bpel package
    BPELPackageManagementServiceSkeleton bpelAdmin = new BPELPackageManagementServiceSkeleton();
    // package list to return
    List<PackageMetadata> packageList = new ArrayList<PackageMetadata>();
    String packageName;
    String versionLessPackageName;
    Artifact artifact;
    for (Artifact.Dependency dep : deps) {
        artifact = dep.getArtifact();
        versionLessPackageName = artifact.getName() + "-" + artifact.getVersion();
        packageName = versionLessPackageName + "-" + bpelAdmin.getLatestVersionInPackage(versionLessPackageName);
        if (packageName == null) {
            continue;
        }
        if (BPELAppDeployer.BPEL_TYPE.equals(artifact.getType())) {
            PackageMetadata packageMetadata = new PackageMetadata();
            packageMetadata.setPackageName(packageName);
            // get the list of processes
            List<String> processList = new ArrayList<String>();
            PackageType packageType = bpelAdmin.listProcessesInPackage(packageName);
            for (Version_type0 packageVersion : packageType.getVersions().getVersion()) {
                if (packageVersion.getName().equals(packageName)) {
                    for (LimitedProcessInfoType process : packageVersion.getProcesses().getProcess()) {
                        processList.add(process.getPid());
                    }
                }
            }
            String[] processes = new String[processList.size()];
            packageMetadata.setProcessList(processList.toArray(processes));
            packageList.add(packageMetadata);
        }
    }
    // convert the List into an array
    data.setPackages(packageList.toArray(new PackageMetadata[packageList.size()]));
    return data;
}
Also used : Version_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.Version_type0) ArrayList(java.util.ArrayList) CarbonApplication(org.wso2.carbon.application.deployer.CarbonApplication) LimitedProcessInfoType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedProcessInfoType) Artifact(org.wso2.carbon.application.deployer.config.Artifact) BPELPackageManagementServiceSkeleton(org.wso2.carbon.bpel.core.ode.integration.mgt.services.BPELPackageManagementServiceSkeleton) PackageType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PackageType)

Aggregations

Artifact (org.wso2.carbon.application.deployer.config.Artifact)8 Deployer (org.apache.axis2.deployment.Deployer)6 DeploymentException (org.apache.axis2.deployment.DeploymentException)6 CappFile (org.wso2.carbon.application.deployer.config.CappFile)6 File (java.io.File)4 DeploymentFileData (org.apache.axis2.deployment.repository.util.DeploymentFileData)3 ArrayList (java.util.ArrayList)2 CarbonApplication (org.wso2.carbon.application.deployer.CarbonApplication)2 BPELPackageManagementServiceSkeleton (org.wso2.carbon.bpel.core.ode.integration.mgt.services.BPELPackageManagementServiceSkeleton)1 LimitedProcessInfoType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.LimitedProcessInfoType)1 PackageType (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.PackageType)1 Version_type0 (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.Version_type0)1 HumanTaskPackageManagementSkeleton (org.wso2.carbon.humantask.skeleton.mgt.services.HumanTaskPackageManagementSkeleton)1 Task_type0 (org.wso2.carbon.humantask.skeleton.mgt.services.types.Task_type0)1