Search in sources :

Example 11 with DeploymentException

use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.

the class WorkflowServiceImpl method reject.

@Override
@SuppressWarnings("unchecked")
@ValidateParams
public ResultTO reject(@ValidateStringParam(name = "site") String site, String request) throws ServiceLayerException {
    ResultTO result = new ResultTO();
    try {
        String approver = securityService.getCurrentUser();
        JSONObject requestObject = JSONObject.fromObject(request);
        String reason = (requestObject.containsKey(JSON_KEY_REASON)) ? requestObject.getString(JSON_KEY_REASON) : "";
        JSONArray items = requestObject.getJSONArray(JSON_KEY_ITEMS);
        String scheduledDate = null;
        if (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) {
            scheduledDate = requestObject.getString(JSON_KEY_SCHEDULED_DATE);
        }
        int length = items.size();
        if (length > 0) {
            SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_WORKFLOW_WITH_TZ);
            List<DmDependencyTO> submittedItems = new ArrayList<DmDependencyTO>();
            for (int index = 0; index < length; index++) {
                String stringItem = items.optString(index);
                // JSONObject item = items.getJSONObject(index);
                // getSubmittedItem(site, item, format, scheduledDate);
                DmDependencyTO submittedItem = null;
                submittedItem = getSubmittedItem(site, stringItem, format, scheduledDate, null);
                submittedItems.add(submittedItem);
            }
            List<String> paths = new ArrayList<String>();
            List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
            for (DmDependencyTO goLiveItem : submittedItems) {
                if (contentService.contentExists(site, goLiveItem.getUri())) {
                    paths.add(goLiveItem.getUri());
                }
                AuditLogParameter auditLogParameter = new AuditLogParameter();
                auditLogParameter.setTargetId(site + ":" + goLiveItem.getUri());
                auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
                auditLogParameter.setTargetValue(goLiveItem.getUri());
                auditLogParameters.add(auditLogParameter);
            }
            objectStateService.setSystemProcessingBulk(site, paths, true);
            Set<String> cancelPaths = new HashSet<String>();
            cancelPaths.addAll(paths);
            deploymentService.cancelWorkflowBulk(site, cancelPaths);
            reject(site, submittedItems, reason, approver);
            SiteFeed siteFeed = siteService.getSite(site);
            AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
            auditLog.setOperation(OPERATION_REJECT);
            auditLog.setActorId(approver);
            auditLog.setSiteId(siteFeed.getId());
            auditLog.setPrimaryTargetId(site);
            auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
            auditLog.setPrimaryTargetValue(site);
            auditLog.setParameters(auditLogParameters);
            auditServiceInternal.insertAuditLog(auditLog);
            objectStateService.setSystemProcessingBulk(site, paths, false);
            result.setSuccess(true);
            result.setStatus(200);
            result.setMessage(notificationService.getNotificationMessage(site, NotificationMessageType.CompleteMessages, NotificationService.COMPLETE_REJECT, Locale.ENGLISH));
        } else {
            result.setSuccess(false);
            result.setMessage("No items provided for preparation.");
        }
    } catch (JSONException | DeploymentException e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
    }
    return result;
}
Also used : JSONArray(net.sf.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(net.sf.json.JSONException) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) ResultTO(org.craftercms.studio.api.v1.to.ResultTO) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) JSONObject(net.sf.json.JSONObject) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 12 with DeploymentException

use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.

the class BlobAwareContentRepository method publish.

@Override
public void publish(String site, String sandboxBranch, List<DeploymentItemTO> deploymentItems, String environment, String author, String comment) throws DeploymentException {
    logger.debug("Publishing items {0} to environment {1} in site {2}", deploymentItems, environment, site);
    Map<String, StudioBlobStore> stores = new LinkedHashMap<>();
    MultiValueMap<String, DeploymentItemTO> items = new LinkedMultiValueMap<>();
    List<DeploymentItemTO> localItems = new LinkedList<>();
    try {
        for (DeploymentItemTO item : deploymentItems) {
            StudioBlobStore store = getBlobStore(site, item.getPath());
            if (store != null) {
                stores.putIfAbsent(store.getId(), store);
                items.add(store.getId(), item);
                localItems.add(mapDeploymentItem(item));
            } else {
                localItems.add(item);
            }
        }
        for (String storeId : stores.keySet()) {
            logger.debug("Publishing blobs to environment {0} using store {1} for site {2}", environment, storeId, site);
            stores.get(storeId).publish(site, sandboxBranch, items.get(storeId), environment, author, comment);
        }
        logger.debug("Publishing local files to environment {0} for site {1}", environment, site);
        localRepositoryV2.publish(site, sandboxBranch, localItems, environment, author, comment);
    } catch (Exception e) {
        throw new DeploymentException("Error during deployment to environment " + environment + " for site " + site, e);
    }
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) StudioBlobStore(org.craftercms.studio.api.v2.repository.blob.StudioBlobStore) DeploymentItemTO(org.craftercms.studio.api.v1.to.DeploymentItemTO) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) LinkedList(java.util.LinkedList) ConfigurationException(org.craftercms.commons.config.ConfigurationException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) IOException(java.io.IOException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException) RepositoryLockedException(org.craftercms.studio.api.v2.exception.RepositoryLockedException) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with DeploymentException

use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.

the class StudioPublisherTask method processPublishingRequest.

private void processPublishingRequest(String siteId, String environment, PublishRequest item, List<DeploymentItemTO> completeDeploymentItemList, Set<String> processedPaths) throws ServiceLayerException, DeploymentException {
    List<DeploymentItemTO> missingDependencies = new ArrayList<DeploymentItemTO>();
    Set<String> missingDependenciesPaths = new HashSet<String>();
    String statusMessage;
    try {
        List<DeploymentItemTO> deploymentItemList = new ArrayList<DeploymentItemTO>();
        logger.debug("Processing [{0}] content item for site \"{1}\"", item.getPath(), siteId);
        DeploymentItemTO deploymentItem = publishingManager.processItem(item);
        if (deploymentItem != null) {
            deploymentItemList.add(deploymentItem);
        }
        logger.debug("Processing COMPLETE [{0}] content item for site \"{1}\"", item.getPath(), siteId);
        if (isMandatoryDependenciesCheckEnabled()) {
            logger.debug("Processing Mandatory Deps [{0}] content item for site " + "\"{1}\"", item.getPath(), siteId);
            missingDependencies.addAll(publishingManager.processMandatoryDependencies(item, processedPaths, missingDependenciesPaths));
            logger.debug("Processing Mandatory Dependencies COMPLETE [{0}]" + " content item for site \"{1}\"", item.getPath(), siteId);
        }
        deploymentItemList.addAll(missingDependencies);
        completeDeploymentItemList.addAll(deploymentItemList);
    } catch (DeploymentException err) {
        logger.error("Error while executing deployment to environment store for site \"{0}\",", err, siteId);
        publishingManager.markItemsReady(siteId, environment, Arrays.asList(item));
        siteService.enablePublishing(siteId, false);
        statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_ERROR);
        siteService.updatePublishingStatusMessage(siteId, ERROR, statusMessage);
        throw err;
    } catch (Exception err) {
        logger.error("Unexpected error while executing deployment to environment " + "store for site \"{0}\", ", err, siteId);
        publishingManager.markItemsReady(siteId, environment, Arrays.asList(item));
        siteService.enablePublishing(siteId, false);
        statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_ERROR);
        siteService.updatePublishingStatusMessage(siteId, ERROR, statusMessage);
        throw err;
    }
}
Also used : DeploymentItemTO(org.craftercms.studio.api.v1.to.DeploymentItemTO) ArrayList(java.util.ArrayList) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) HashSet(java.util.HashSet)

Example 14 with DeploymentException

use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.

the class DeploymentServiceImpl method deploy.

@Override
@ValidateParams
public void deploy(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<String> paths, ZonedDateTime scheduledDate, @ValidateStringParam(name = "approver") String approver, @ValidateStringParam(name = "submissionComment") String submissionComment, final boolean scheduleDateNow) throws DeploymentException {
    if (scheduledDate != null && scheduledDate.isAfter(ZonedDateTime.now(ZoneOffset.UTC))) {
        objectStateService.transitionBulk(site, paths, SUBMIT_WITHOUT_WORKFLOW_SCHEDULED, NEW_SUBMITTED_NO_WF_SCHEDULED);
    }
    List<String> newPaths = new ArrayList<String>();
    List<String> updatedPaths = new ArrayList<String>();
    List<String> movedPaths = new ArrayList<String>();
    Map<String, List<String>> groupedPaths = new HashMap<String, List<String>>();
    for (String p : paths) {
        boolean isFolder = contentRepository.isFolder(site, p);
        if (isFolder) {
            logger.debug("Content item at path " + p + " for site " + site + " is folder and will not be added to publishing queue.");
        } else {
            if (objectStateService.isNew(site, p)) {
                newPaths.add(p);
            } else if (objectMetadataManager.isRenamed(site, p)) {
                movedPaths.add(p);
            } else {
                updatedPaths.add(p);
            }
        }
    }
    groupedPaths.put(PublishRequest.Action.NEW, newPaths);
    groupedPaths.put(PublishRequest.Action.MOVE, movedPaths);
    groupedPaths.put(PublishRequest.Action.UPDATE, updatedPaths);
    List<PublishRequest> items = createItems(site, environment, groupedPaths, scheduledDate, approver, submissionComment);
    for (PublishRequest item : items) {
        publishRequestMapper.insertItemForDeployment(item);
    }
    objectStateService.setSystemProcessingBulk(site, paths, false);
    // We need to pick up this on Inserting , not on execution!
    try {
        sendContentApprovalEmail(items, scheduleDateNow);
    } catch (Exception errNotify) {
        logger.error("Error sending approval notification ", errNotify);
    }
    String statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_QUEUED);
    try {
        siteService.updatePublishingStatusMessage(site, QUEUED, statusMessage);
    } catch (SiteNotFoundException e) {
        logger.error("Error updating publishing status for site " + site);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FastArrayList(org.apache.commons.collections.FastArrayList) List(java.util.List) ArrayList(java.util.ArrayList) FastArrayList(org.apache.commons.collections.FastArrayList) PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) EnvironmentNotFoundException(org.craftercms.studio.api.v1.exception.EnvironmentNotFoundException) CommitNotFoundException(org.craftercms.studio.api.v1.exception.CommitNotFoundException) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException) AuthenticationException(org.craftercms.studio.api.v1.exception.security.AuthenticationException) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 15 with DeploymentException

use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.

the class DeploymentServiceImpl method delete.

@Override
@ValidateParams
public void delete(@ValidateStringParam(name = "site") String site, List<String> paths, @ValidateStringParam(name = "approver") String approver, ZonedDateTime scheduledDate, String submissionComment) throws DeploymentException, SiteNotFoundException {
    if (scheduledDate != null && scheduledDate.isAfter(ZonedDateTime.now(ZoneOffset.UTC))) {
        objectStateService.transitionBulk(site, paths, DELETE, NEW_DELETED);
    }
    Set<String> environments = getAllPublishedEnvironments(site);
    for (String environment : environments) {
        List<PublishRequest> items = createDeleteItems(site, environment, paths, approver, scheduledDate, submissionComment);
        for (PublishRequest item : items) {
            publishRequestMapper.insertItemForDeployment(item);
        }
    }
    objectStateService.setSystemProcessingBulk(site, paths, false);
    String statusMessage = studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_QUEUED);
    try {
        siteService.updatePublishingStatusMessage(site, QUEUED, statusMessage);
    } catch (SiteNotFoundException e) {
        logger.error("Error updating publishing status for site " + site);
    }
}
Also used : PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)12 DeploymentItemTO (org.craftercms.studio.api.v1.to.DeploymentItemTO)10 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)9 ArrayList (java.util.ArrayList)8 PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)8 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)6 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)6 ZonedDateTime (java.time.ZonedDateTime)5 HashSet (java.util.HashSet)5 CryptoException (org.craftercms.commons.crypto.CryptoException)4 IOException (java.io.IOException)3 RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)3 Test (org.testng.annotations.Test)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)2 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)2 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)2 InvalidRemoteRepositoryCredentialsException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteRepositoryCredentialsException)2 InvalidRemoteRepositoryException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteRepositoryException)2 RemoteRepositoryNotFoundException (org.craftercms.studio.api.v1.exception.repository.RemoteRepositoryNotFoundException)2