Search in sources :

Example 6 with Deployer

use of org.craftercms.studio.api.v2.deployment.Deployer in project carbon-mediation by wso2.

the class SynapseAppDeployer method undeployArtifactType.

/**
 * Un deploy a given artifact type
 * @param carbonApplication
 * @param axisConfig
 * @param artifacts
 */
private void undeployArtifactType(CarbonApplication carbonApplication, AxisConfiguration axisConfig, List<Artifact.Dependency> artifacts) {
    for (Artifact.Dependency dep : artifacts) {
        Artifact artifact = dep.getArtifact();
        if (!validateArtifact(artifact)) {
            continue;
        }
        Deployer deployer;
        String artifactDir = null;
        if (SynapseAppDeployerConstants.MEDIATOR_TYPE.endsWith(artifact.getType())) {
            deployer = getClassMediatorDeployer(axisConfig);
        } else if (SynapseAppDeployerConstants.SYNAPSE_LIBRARY_TYPE.equals(artifact.getType())) {
            deployer = getSynapseLibraryDeployer(axisConfig);
        } else {
            String artifactDirName = getArtifactDirName(artifact);
            if (artifactDirName == null) {
                continue;
            }
            deployer = getDeployer(axisConfig, artifactDirName);
            artifactDir = getArtifactDirPath(axisConfig, artifactDirName);
        }
        if (deployer != null && AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED.equals(artifact.getDeploymentStatus())) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactName = artifact.getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            File artifactInRepo = new File(artifactDir + File.separator + fileName);
            try {
                // version in its name in the synapse config (ex: MyAPI:v1 instead of MyAPI)
                if (SynapseAppDeployerConstants.API_TYPE.equals(artifact.getType())) {
                    Properties properties = new Properties();
                    SynapseArtifactDeploymentStore deploymentStore = getSynapseConfiguration(axisConfig).getArtifactDeploymentStore();
                    if (deploymentStore != null) {
                        properties.put(SynapseConstants.CLASS_MEDIATOR_LOADERS, deploymentStore.getClassMediatorClassLoaders());
                    }
                    artifactName = extractApiNameFromArtifact(artifact, fileName, properties);
                }
                if (SynapseAppDeployerConstants.MEDIATOR_TYPE.endsWith(artifact.getType())) {
                    if (deployer instanceof AbstractSynapseArtifactDeployer) {
                        ((AbstractSynapseArtifactDeployer) deployer).setCustomLog(carbonApplication.getAppName(), AppDeployerUtils.getTenantIdLogString(AppDeployerUtils.getTenantId()));
                    }
                    deployer.undeploy(artifactPath);
                } else if (SynapseAppDeployerConstants.SYNAPSE_LIBRARY_TYPE.equals(artifact.getType())) {
                    String libQName = getArtifactName(artifactPath, axisConfig);
                    deleteImport(libQName, axisConfig);
                    deployer.undeploy(artifactPath);
                } else if (SynapseAppDeployerConstants.SEQUENCE_TYPE.equals(artifact.getType()) && handleMainFaultSeqUndeployment(artifact, axisConfig)) {
                } else if (artifactInRepo.exists()) {
                    log.info("Deleting artifact at " + artifactInRepo.getAbsolutePath());
                    if (!artifactInRepo.delete()) {
                        log.error("Unable to delete " + artifactInRepo.getAbsolutePath());
                    }
                } else {
                    // use reflection to avoid having synapse as a dependency
                    Class[] paramString = new Class[1];
                    paramString[0] = String.class;
                    Method method = deployer.getClass().getDeclaredMethod("undeploySynapseArtifact", paramString);
                    method.invoke(deployer, artifactName);
                }
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_PENDING);
                File artifactFile = new File(artifactPath);
                if (artifactFile.exists() && !artifactFile.delete()) {
                    log.warn("Couldn't delete App artifact file : " + artifactPath);
                }
            } catch (Exception e) {
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                log.error("Error occured while trying to un deploy : " + artifactName);
            }
        }
    }
}
Also used : SynapseArtifactDeploymentStore(org.apache.synapse.deployers.SynapseArtifactDeploymentStore) Method(java.lang.reflect.Method) Properties(java.util.Properties) CappFile(org.wso2.carbon.application.deployer.config.CappFile) File(java.io.File) AbstractSynapseArtifactDeployer(org.apache.synapse.deployers.AbstractSynapseArtifactDeployer) Artifact(org.wso2.carbon.application.deployer.config.Artifact) Deployer(org.apache.axis2.deployment.Deployer) AbstractSynapseArtifactDeployer(org.apache.synapse.deployers.AbstractSynapseArtifactDeployer) LibraryArtifactDeployer(org.apache.synapse.deployers.LibraryArtifactDeployer) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentException(org.apache.axis2.deployment.DeploymentException) SynapseException(org.apache.synapse.SynapseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Example 7 with Deployer

use of org.craftercms.studio.api.v2.deployment.Deployer in project wso2-synapse by wso2.

the class ConnectorDeployer method deployConnectorResources.

/**
 * Extract and load connector resources.
 *
 * @param connectorList list which has connector resources
 */
static void deployConnectorResources(List<String> connectorList) {
    for (int x = 0; x < connectorList.size(); x++) {
        String javaTempTestDir = System.getProperty(Constants.PRAM_TEMP_DIR) + File.separator + Constants.CONNECTOR_TEST_FOLDER;
        createDir(javaTempTestDir);
        BufferedOutputStream out = null;
        try {
            byte[] decodedConnector = Base64.decode(connectorList.get(x));
            String connectorZip = javaTempTestDir + File.separator + "connector-" + x + ".zip";
            out = new BufferedOutputStream(new FileOutputStream(connectorZip), 4096);
            out.write(decodedConnector);
            // deploy connector zip
            LibDeployerUtils.createSynapseLibrary(connectorZip);
            SynapseConfiguration configuration = UnitTestingExecutor.getExecuteInstance().getSynapseConfiguration();
            AxisConfiguration axisConfiguration = configuration.getAxisConfiguration();
            Deployer deployer = getSynapseLibraryDeployer(axisConfiguration);
            deployer.deploy(new DeploymentFileData(new File(connectorZip), deployer));
            try {
                String artifactName = getArtifactName(connectorZip, axisConfiguration);
                if (artifactName != null) {
                    if (configuration.getSynapseImports().get(artifactName) == null) {
                        String libName = artifactName.substring(artifactName.lastIndexOf("}") + 1);
                        String libraryPackage = artifactName.substring(1, artifactName.lastIndexOf("}"));
                        updateStatus(artifactName, libName, libraryPackage, "enabled", axisConfiguration);
                    }
                }
            } catch (AxisFault axisFault) {
                log.error("Unable to update status for the synapse library : ", axisFault);
            }
        } catch (DeploymentException e) {
            log.error("Error while deploying the synapse library : ", e);
        } catch (IOException e) {
            log.error("Error while writing the output stream of connector zip file", e);
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    log.error("Error while closing the output stream of connector zip file", e);
                }
            }
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) DeploymentFileData(org.apache.axis2.deployment.repository.util.DeploymentFileData) IOException(java.io.IOException) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) FileOutputStream(java.io.FileOutputStream) DeploymentException(org.apache.axis2.deployment.DeploymentException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) LibraryArtifactDeployer(org.apache.synapse.deployers.LibraryArtifactDeployer) Deployer(org.apache.axis2.deployment.Deployer)

Example 8 with Deployer

use of org.craftercms.studio.api.v2.deployment.Deployer in project carbon-business-process by wso2.

the class BPELAppDeployer method undeployArtifacts.

/**
 * Check the artifact type and if it is a BPEL, delete the file from the BPEL
 * deployment hot folder
 *
 * @param carbonApp  - CarbonApplication instance to check for BPEL artifacts
 * @param axisConfig - - axisConfig of the current tenant
 */
public void undeployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) {
    List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
    for (Artifact.Dependency dep : artifacts) {
        Deployer deployer;
        Artifact artifact = dep.getArtifact();
        if (artifact == null) {
            continue;
        }
        if (BPEL_TYPE.equals(artifact.getType())) {
            deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, BPEL_DIR, "zip");
        } else {
            continue;
        }
        // loop through all dependencies
        List<CappFile> files = artifact.getFiles();
        if (files.size() != 1) {
            log.error("A BPEL workflow must have a single file. But " + files.size() + " files found.");
            continue;
        }
        if (deployer != null && AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED.equals(artifact.getDeploymentStatus())) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            try {
                File artifactFile = new File(artifactPath);
                if (artifactFile.exists() && !artifactFile.delete()) {
                    log.warn("Couldn't delete App artifact file : " + artifactPath);
                }
                deployer.undeploy(artifactPath);
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_PENDING);
            } catch (DeploymentException e) {
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                log.error("Error occured while trying to un deploy : " + artifact.getName());
            }
        }
    }
}
Also used : 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 9 with Deployer

use of org.craftercms.studio.api.v2.deployment.Deployer in project carbon-business-process by wso2.

the class BPELAppDeployer method deployArtifacts.

/**
 * Check the artifact type and if it is a BPEL, copy it to the BPEL deployment hot folder
 *
 * @param carbonApp  - CarbonApplication instance to check for BPEL 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 artifacts
    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 (BPEL_TYPE.equals(artifact.getType())) {
            deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, BPEL_DIR, "zip");
        } else {
            continue;
        }
        List<CappFile> files = artifact.getFiles();
        if (files.size() != 1) {
            log.error("BPEL workflows 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);
            } 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 10 with Deployer

use of org.craftercms.studio.api.v2.deployment.Deployer 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)

Aggregations

Deployer (org.apache.axis2.deployment.Deployer)12 DeploymentException (org.apache.axis2.deployment.DeploymentException)11 Artifact (org.wso2.carbon.application.deployer.config.Artifact)10 CappFile (org.wso2.carbon.application.deployer.config.CappFile)10 File (java.io.File)9 DeploymentFileData (org.apache.axis2.deployment.repository.util.DeploymentFileData)7 IOException (java.io.IOException)6 LibraryArtifactDeployer (org.apache.synapse.deployers.LibraryArtifactDeployer)6 AbstractSynapseArtifactDeployer (org.apache.synapse.deployers.AbstractSynapseArtifactDeployer)5 CryptoException (org.craftercms.commons.crypto.CryptoException)4 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)4 RestServiceException (org.craftercms.commons.rest.RestServiceException)4 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)4 BlueprintNotFoundException (org.craftercms.studio.api.v1.exception.BlueprintNotFoundException)4 DeployerTargetException (org.craftercms.studio.api.v1.exception.DeployerTargetException)4 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)4 SiteAlreadyExistsException (org.craftercms.studio.api.v1.exception.SiteAlreadyExistsException)4 SiteCreationException (org.craftercms.studio.api.v1.exception.SiteCreationException)4 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)4 InvalidRemoteRepositoryCredentialsException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteRepositoryCredentialsException)4