Search in sources :

Example 71 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-mediation by wso2.

the class SynapseApplicationAdmin method getSynapseAppData.

/**
 * Gives a SynapseApplicationMetadata object with all synapse artifacts deployed through the
 * given app. This can consist of proxy services, endpoints etc..
 *
 * @param appName - input app name
 * @return - SynapseApplicationMetadata object with found artifact info
 * @throws Exception - error on retrieving metadata
 */
public SynapseApplicationMetadata getSynapseAppData(String appName) throws Exception {
    SynapseApplicationMetadata data = new SynapseApplicationMetadata();
    String tenantId = AppDeployerUtils.getTenantIdString(getAxisConfig());
    SynapseConfigAdmin synapseConfigAdmin = new SynapseConfigAdmin();
    // Check whether there is an application in the system from the given name
    ArrayList<CarbonApplication> appList = SynapseAppServiceComponent.getAppManager().getCarbonApps(tenantId);
    CarbonApplication currentApplication = null;
    for (CarbonApplication application : appList) {
        if (appName.equals(application.getAppNameWithVersion())) {
            data.setAppName(application.getAppName());
            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);
    }
    List<String> sequenceList = new ArrayList<String>();
    List<EndpointMetadata> endpointList = new ArrayList<EndpointMetadata>();
    List<String> proxyList = new ArrayList<String>();
    List<String> leList = new ArrayList<String>();
    List<String> eventList = new ArrayList<String>();
    List<String> mediatorList = new ArrayList<String>();
    List<TaskMetadata> taskList = new ArrayList<TaskMetadata>();
    List<String> apiList = new ArrayList<String>();
    List<String> inboundEPList = new ArrayList<String>();
    List<String> messageStoreList = new ArrayList<String>();
    List<String> messageProcessorList = new ArrayList<String>();
    List<Artifact.Dependency> dependencies = currentApplication.getAppConfig().getApplicationArtifact().getDependencies();
    // iterate the dependent artifacts and create metadata elements
    for (Artifact.Dependency dependency : dependencies) {
        Artifact artifact = dependency.getArtifact();
        String type = artifact.getType();
        String instanceName = artifact.getName();
        // if the instance name is null, artifact deployment has failed..
        if (instanceName == null) {
            continue;
        }
        if (SynapseAppDeployerConstants.SEQUENCE_TYPE.equals(type)) {
            sequenceList.add(instanceName);
        } else if (SynapseAppDeployerConstants.ENDPOINT_TYPE.equals(type)) {
            EndpointMetadata endpointMetadata = synapseConfigAdmin.getEndpointMetadata(instanceName);
            if (endpointMetadata != null) {
                endpointList.add(endpointMetadata);
            }
        } else if (SynapseAppDeployerConstants.PROXY_SERVICE_TYPE.equals(type)) {
            proxyList.add(instanceName);
        } else if (SynapseAppDeployerConstants.LOCAL_ENTRY_TYPE.equals(type)) {
            leList.add(instanceName);
        } else if (SynapseAppDeployerConstants.EVENT_SOURCE_TYPE.equals(type)) {
            eventList.add(instanceName);
        } else if (SynapseAppDeployerConstants.MEDIATOR_TYPE.equals(type)) {
            mediatorList.add(instanceName);
        } else if (SynapseAppDeployerConstants.API_TYPE.equals(type)) {
            apiList.add(instanceName);
        } else if (SynapseAppDeployerConstants.INBOUND_ENDPOINT_TYPE.equals(type)) {
            inboundEPList.add(instanceName);
        } else if (SynapseAppDeployerConstants.MESSAGE_PROCESSOR_TYPE.equals(type)) {
            messageProcessorList.add(instanceName);
        } else if (SynapseAppDeployerConstants.MESSAGE_STORE_TYPE.equals(type)) {
            messageStoreList.add(instanceName);
        } else if (SynapseAppDeployerConstants.TASK_TYPE.equals(type)) {
            TaskMetadata taskMetadata = synapseConfigAdmin.getTaskMetaData(instanceName);
            if (taskMetadata != null) {
                taskList.add(taskMetadata);
            }
        }
    }
    // Set found artifacts in the data object
    data.setSequences(sequenceList.toArray(new String[sequenceList.size()]));
    data.setEndpoints(endpointList.toArray(new EndpointMetadata[endpointList.size()]));
    data.setProxyServices(proxyList.toArray(new String[proxyList.size()]));
    data.setLocalEntries(leList.toArray(new String[leList.size()]));
    data.setEvents(eventList.toArray(new String[eventList.size()]));
    data.setMediators(mediatorList.toArray(new String[mediatorList.size()]));
    data.setTasks(taskList.toArray(new TaskMetadata[taskList.size()]));
    data.setApis(apiList.toArray(new String[apiList.size()]));
    data.setInboundEPs(inboundEPList.toArray(new String[inboundEPList.size()]));
    data.setMessageProcessors(messageProcessorList.toArray(new String[messageProcessorList.size()]));
    data.setMessageStores(messageStoreList.toArray(new String[messageStoreList.size()]));
    return data;
}
Also used : ArrayList(java.util.ArrayList) CarbonApplication(org.wso2.carbon.application.deployer.CarbonApplication) SynapseConfigAdmin(org.wso2.carbon.application.mgt.synapse.internal.SynapseConfigAdmin) Artifact(org.wso2.carbon.application.deployer.config.Artifact)

Example 72 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-mediation by wso2.

the class FileRegistryResourceDeployer method deployArtifacts.

@Override
public void deployArtifacts(CarbonApplication carbonApplication, AxisConfiguration axisConfiguration) throws DeploymentException {
    ApplicationConfiguration appConfig = carbonApplication.getAppConfig();
    List<Artifact.Dependency> deps = appConfig.getApplicationArtifact().getDependencies();
    List<Artifact> artifacts = new ArrayList<Artifact>();
    for (Artifact.Dependency dep : deps) {
        if (dep.getArtifact() != null) {
            artifacts.add(dep.getArtifact());
        }
    }
    deployRegistryArtifacts(artifacts, carbonApplication.getAppNameWithVersion());
}
Also used : ArrayList(java.util.ArrayList) ApplicationConfiguration(org.wso2.carbon.application.deployer.config.ApplicationConfiguration) Artifact(org.wso2.carbon.application.deployer.config.Artifact)

Example 73 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-mediation by wso2.

the class SynapseAppDeployer method deployClassMediators.

/**
 * Deploy class mediators contains in the CApp
 *
 * @param artifacts List of Artifacts contains in the capp
 * @param axisConfig AxisConfiguration of the current tenant
 * @throws DeploymentException if something goes wrong while deployment
 */
private void deployClassMediators(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig) throws DeploymentException {
    for (Artifact.Dependency dependency : artifacts) {
        Artifact artifact = dependency.getArtifact();
        if (!validateArtifact(artifact)) {
            continue;
        }
        if (SynapseAppDeployerConstants.MEDIATOR_TYPE.endsWith(artifact.getType())) {
            Deployer deployer = getClassMediatorDeployer(axisConfig);
            if (deployer != null) {
                artifact.setRuntimeObjectName(artifact.getName());
                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) CappFile(org.wso2.carbon.application.deployer.config.CappFile) File(java.io.File) 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)

Example 74 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-mediation by wso2.

the class SynapseAppDeployer method deployArtifactType.

/**
 * This deploys artifacts when a list of artifacts is provided
 *
 * @param artifacts - List of artifacts which should be deployed
 * @param carbonApp  - CarbonApplication instance to check for artifacts
 * @param axisConfig - AxisConfiguration of the current tenant
 * @throws DeploymentException if some error occurs while deployment
 */
public void deployArtifactType(List<Artifact.Dependency> artifacts, CarbonApplication carbonApp, AxisConfiguration axisConfig) throws DeploymentException {
    for (Artifact.Dependency dep : artifacts) {
        Artifact artifact = dep.getArtifact();
        String artifactDirName = getArtifactDirName(artifact);
        if (!validateArtifact(artifact) || artifactDirName == null) {
            continue;
        }
        Deployer deployer = getDeployer(axisConfig, artifactDirName);
        String artifactDir = getArtifactDirPath(axisConfig, artifactDirName);
        artifact.setRuntimeObjectName(artifact.getName());
        if (deployer != null) {
            String fileName = artifact.getFiles().get(0).getName();
            String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
            File artifactInRepo = new File(artifactDir + File.separator + fileName);
            if (SynapseAppDeployerConstants.SEQUENCE_TYPE.equals(artifact.getType()) && handleMainFaultSeqDeployment(artifact, axisConfig)) {
            } else if (artifactInRepo.exists()) {
                log.warn("Artifact " + fileName + " already found in " + artifactInRepo.getAbsolutePath() + ". Ignoring CAPP's artifact");
                artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
            } else {
                try {
                    setCustomLogContent(deployer, carbonApp);
                    deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                } catch (Throwable e) {
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                    if (!(e instanceof DeploymentException)) {
                        throw new DeploymentException(e);
                    } else {
                        throw e;
                    }
                } finally {
                    // clear the log appender once deployment is finished to avoid appending the
                    // same log to other classes.
                    setCustomLogContent(deployer, null);
                    CustomLogSetter.getInstance().clearThreadLocalContent();
                }
            }
        }
    }
}
Also used : DeploymentFileData(org.apache.axis2.deployment.repository.util.DeploymentFileData) DeploymentException(org.apache.axis2.deployment.DeploymentException) CappFile(org.wso2.carbon.application.deployer.config.CappFile) File(java.io.File) 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)

Example 75 with Artifacts

use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-mediation by wso2.

the class SynapseAppDeployer method deploySynapseLibrary.

/**
 * Deploy synapse libraries contains in the CApp
 *
 * @param artifacts  List of Artifacts contains in the capp
 * @param axisConfig AxisConfiguration of the current tenant
 * @throws DeploymentException if something goes wrong while deployment
 */
private void deploySynapseLibrary(List<Artifact.Dependency> artifacts, AxisConfiguration axisConfig) throws DeploymentException {
    for (Artifact.Dependency dependency : artifacts) {
        Artifact artifact = dependency.getArtifact();
        if (!validateArtifact(artifact)) {
            continue;
        }
        if (SynapseAppDeployerConstants.SYNAPSE_LIBRARY_TYPE.equals(artifact.getType())) {
            Deployer deployer = getSynapseLibraryDeployer(axisConfig);
            if (deployer != null) {
                artifact.setRuntimeObjectName(artifact.getName());
                String fileName = artifact.getFiles().get(0).getName();
                String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
                String artifactDir = getArtifactDirPath(axisConfig, SynapseAppDeployerConstants.SYNAPSE_LIBS);
                File artifactInRepo = new File(artifactDir + File.separator + fileName);
                if (artifactInRepo.exists()) {
                    log.warn("Synapse Library " + fileName + " already found in " + artifactInRepo.getAbsolutePath() + ". Ignoring CAPP's artifact");
                    artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                } else {
                    try {
                        deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
                        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
                        try {
                            String artifactName = getArtifactName(artifactPath, axisConfig);
                            SynapseConfiguration configuration = getSynapseConfiguration(axisConfig);
                            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, ServiceBusConstants.ENABLED, axisConfig);
                                }
                            }
                        } catch (AxisFault axisFault) {
                            log.error("Unable to update status for the synapse library : " + axisFault.getMessage());
                        } catch (NullPointerException nullException) {
                            log.error("Error while getting qualified name of the synapse library : " + nullException.getMessage());
                        }
                    } catch (DeploymentException e) {
                        artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
                        log.error("Error while deploying the synapse library : " + e.getMessage());
                        throw e;
                    }
                }
            }
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) DeploymentFileData(org.apache.axis2.deployment.repository.util.DeploymentFileData) DeploymentException(org.apache.axis2.deployment.DeploymentException) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) CappFile(org.wso2.carbon.application.deployer.config.CappFile) File(java.io.File) 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)

Aggregations

File (java.io.File)23 IOException (java.io.IOException)18 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)18 ArrayList (java.util.ArrayList)17 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)16 Operation (io.swagger.v3.oas.annotations.Operation)15 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)15 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)15 Response (javax.ws.rs.core.Response)15 Artifact (org.wso2.carbon.application.deployer.config.Artifact)15 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 DeploymentException (org.apache.axis2.deployment.DeploymentException)11 CappFile (org.wso2.carbon.application.deployer.config.CappFile)11 Deployer (org.apache.axis2.deployment.Deployer)10 ArtifactSynchronizerException (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)10 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)10 InputStream (java.io.InputStream)9 FileInputStream (java.io.FileInputStream)7 APIRuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto)7 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7