Search in sources :

Example 11 with Deployer

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

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

the class SynapseAppDeployer method getDeployer.

/**
 * Finds the correct deployer for the given artifact type
 *
 * @param axisConfig - AxisConfiguration instance
 * @return Deployer instance
 */
private Deployer getDeployer(AxisConfiguration axisConfig, String directory) {
    Deployer deployer = null;
    // access the deployment engine through axis config
    DeploymentEngine deploymentEngine = (DeploymentEngine) axisConfig.getConfigurator();
    String tenantId = AppDeployerUtils.getTenantIdString(axisConfig);
    SynapseEnvironmentService environmentService = DataHolder.getInstance().getSynapseEnvironmentService(Integer.parseInt(tenantId));
    if (environmentService != null) {
        String synapseConfigPath = ServiceBusUtils.getSynapseConfigAbsPath(environmentService.getSynapseEnvironment().getServerContextInformation());
        String endpointDirPath = synapseConfigPath + File.separator + directory;
        deployer = deploymentEngine.getDeployer(endpointDirPath, ServiceBusConstants.ARTIFACT_EXTENSION);
    }
    return deployer;
}
Also used : DeploymentEngine(org.apache.axis2.deployment.DeploymentEngine) SynapseEnvironmentService(org.wso2.carbon.mediation.initializer.services.SynapseEnvironmentService) Deployer(org.apache.axis2.deployment.Deployer) AbstractSynapseArtifactDeployer(org.apache.synapse.deployers.AbstractSynapseArtifactDeployer) LibraryArtifactDeployer(org.apache.synapse.deployers.LibraryArtifactDeployer)

Example 13 with Deployer

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

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

Example 15 with Deployer

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

the class SiteServiceImpl method createSiteFromBlueprint.

@Override
@ValidateParams
public void createSiteFromBlueprint(@ValidateStringParam(name = "blueprintId") String blueprintId, @ValidateNoTagsParam(name = "siteName") String siteName, @ValidateStringParam(name = "siteId", maxLength = 50, whitelistedPatterns = "[a-z0-9\\-]*") String siteId, @ValidateStringParam(name = "sandboxBranch") String sandboxBranch, @ValidateNoTagsParam(name = "desc") String desc, Map<String, String> params, boolean createAsOrphan) throws SiteAlreadyExistsException, SiteCreationException, DeployerTargetException, BlueprintNotFoundException, MissingPluginParameterException {
    if (exists(siteId)) {
        throw new SiteAlreadyExistsException();
    }
    logger.debug("Get blueprint descriptor for: " + blueprintId);
    PluginDescriptor descriptor = sitesServiceInternal.getBlueprintDescriptor(blueprintId);
    if (Objects.isNull(descriptor)) {
        throw new BlueprintNotFoundException();
    }
    logger.debug("Validating blueprint parameters");
    sitesServiceInternal.validateBlueprintParameters(descriptor, params);
    String blueprintLocation = sitesServiceInternal.getBlueprintLocation(blueprintId);
    String searchEngine = descriptor.getPlugin().getSearchEngine();
    logger.debug("Validate site entitlements");
    try {
        entitlementValidator.validateEntitlement(EntitlementType.SITE, 1);
    } catch (EntitlementException e) {
        throw new SiteCreationException("Unable to complete request due to entitlement limits. Please contact " + "your system administrator.", e);
    }
    logger.info("Starting site creation process for site " + siteName + " from " + blueprintId + " blueprint.");
    boolean success = true;
    // We must fail site creation if any of the site creations steps fail and rollback
    // For example: Create site => create Deployer Target (fail) = fail
    // and rollback the whole thing.
    // What we need to do for site creation and the order of execution:
    // 1) deployer target, 2) git repo, 3) database, 4) kick deployer
    String siteUuid = UUID.randomUUID().toString();
    // Create the site in the preview deployer
    logger.info("Creating deployer targets.");
    try {
        deployer.createTargets(siteId, searchEngine);
    } catch (Exception e) {
        success = false;
        String msg = "Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". The required Deployer targets couldn't be created";
        logger.error(msg, e);
        throw new DeployerTargetException(msg, e);
    }
    if (success) {
        try {
            logger.info("Copying site content from blueprint.");
            success = createSiteFromBlueprintGit(blueprintLocation, siteName, siteId, sandboxBranch, desc, params);
            ZonedDateTime now = ZonedDateTime.now();
            logger.debug("Adding site UUID.");
            addSiteUuidFile(siteId, siteUuid);
            logger.info("Adding site record to database for site " + siteId);
            // insert database records
            SiteFeed siteFeed = new SiteFeed();
            siteFeed.setName(siteName);
            siteFeed.setSiteId(siteId);
            siteFeed.setSiteUuid(siteUuid);
            siteFeed.setDescription(desc);
            siteFeed.setPublishingStatus(READY);
            siteFeed.setPublishingStatusMessage(studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_DEFAULT));
            siteFeed.setSandboxBranch(sandboxBranch);
            siteFeed.setSearchEngine(searchEngine);
            siteFeedMapper.createSite(siteFeed);
            String localeAddress = studioClusterUtils.getClusterNodeLocalAddress();
            ClusterMember cm = clusterDao.getMemberByLocalAddress(localeAddress);
            if (Objects.nonNull(cm)) {
                SiteFeed s = getSite(siteId);
                clusterDao.insertClusterSiteSyncRepo(cm.getId(), s.getId(), null, null, null);
            }
            logger.info("Upgrading site.");
            upgradeManager.upgradeSite(siteId);
            // Add default groups
            logger.info("Adding default groups");
            addDefaultGroupsForNewSite(siteId);
            String lastCommitId = contentRepositoryV2.getRepoLastCommitId(siteId);
            String creator = securityService.getCurrentUser();
            long startGetChangeSetCreatedFilesMark = logger.isDebugEnabled() ? System.currentTimeMillis() : 0;
            Map<String, String> createdFiles = contentRepositoryV2.getChangeSetPathsFromDelta(siteId, null, lastCommitId);
            if (logger.isDebugEnabled()) {
                logger.debug("Get change set created files finished in " + (System.currentTimeMillis() - startGetChangeSetCreatedFilesMark) + " milliseconds");
            }
            logger.info("Adding audit log");
            insertCreateSiteAuditLog(siteId, siteName, createdFiles);
            processCreatedFiles(siteId, createdFiles, creator, now, lastCommitId);
            contentRepositoryV2.insertGitLog(siteId, lastCommitId, 1, 1);
            updateLastCommitId(siteId, lastCommitId);
            updateLastVerifiedGitlogCommitId(siteId, lastCommitId);
            updateLastSyncedGitlogCommitId(siteId, lastCommitId);
            logger.info("Reload site configuration");
            reloadSiteConfiguration(siteId);
        } catch (Exception e) {
            success = false;
            logger.error("Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". Rolling back.", e);
            deleteSite(siteId);
            throw new SiteCreationException("Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". Rolling back.");
        }
    }
    if (success) {
        logger.info("Syncing all content to preview.");
        // Now that everything is created, we can sync the preview deployer with the new content
        try {
            deploymentService.syncAllContentToPreview(siteId, true);
        } catch (ServiceLayerException e) {
            logger.error("Error while syncing site: " + siteName + " ID: " + siteId + " to preview. Site was " + "successfully created otherwise. Ignoring.", e);
            throw new SiteCreationException("Error while syncing site: " + siteName + " ID: " + siteId + " to preview. Site was successfully created, but it won't be preview-able until the Preview " + "Deployer is reachable.");
        }
        setSiteState(siteId, STATE_CREATED);
    } else {
        throw new SiteCreationException("Error while creating site: " + siteName + " ID: " + siteId + ".");
    }
    logger.info("Finished creating site " + siteId);
}
Also used : BlueprintNotFoundException(org.craftercms.studio.api.v1.exception.BlueprintNotFoundException) DeployerTargetException(org.craftercms.studio.api.v1.exception.DeployerTargetException) SiteAlreadyExistsException(org.craftercms.studio.api.v1.exception.SiteAlreadyExistsException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) SiteConfigNotFoundException(org.craftercms.studio.api.v1.service.site.SiteConfigNotFoundException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) SiteCreationException(org.craftercms.studio.api.v1.exception.SiteCreationException) MissingPluginParameterException(org.craftercms.studio.api.v2.exception.MissingPluginParameterException) IOException(java.io.IOException) RemoteRepositoryNotFoundException(org.craftercms.studio.api.v1.exception.repository.RemoteRepositoryNotFoundException) UserNotFoundException(org.craftercms.studio.api.v1.exception.security.UserNotFoundException) InvalidRemoteUrlException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException) DeployerTargetException(org.craftercms.studio.api.v1.exception.DeployerTargetException) RestServiceException(org.craftercms.commons.rest.RestServiceException) SiteAlreadyExistsException(org.craftercms.studio.api.v1.exception.SiteAlreadyExistsException) GroupAlreadyExistsException(org.craftercms.studio.api.v1.exception.security.GroupAlreadyExistsException) DocumentException(org.dom4j.DocumentException) EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) BlueprintNotFoundException(org.craftercms.studio.api.v1.exception.BlueprintNotFoundException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException) RemoteRepositoryNotBareException(org.craftercms.studio.api.v1.exception.repository.RemoteRepositoryNotBareException) InvalidRemoteRepositoryCredentialsException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteRepositoryCredentialsException) InvalidRemoteRepositoryException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteRepositoryException) PluginDescriptor(org.craftercms.commons.plugin.model.PluginDescriptor) EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) ZonedDateTime(java.time.ZonedDateTime) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteCreationException(org.craftercms.studio.api.v1.exception.SiteCreationException) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

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