Search in sources :

Example 91 with Property

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property in project carbon-business-process by wso2.

the class TenantProcessStoreImpl method handleUndeployOnSlaveNode.

/**
 * Undeployment scenario in a worker node( Slave ) in the clustered setup
 * When the BPELDeployer get called for undeploying the bpel package, following has already taken place.
 * The package information stored in the registry as well as the zip archive is deleted
 * Process, Instance information have been removed from the ODE database
 * However, on the slave node, the bpel process and the web services associated with the bpel process
 * is still in memory. We need to unload the bpel process and the associated web services
 *
 * @param bpelPackageName bpel package name
 * @return
 */
private int handleUndeployOnSlaveNode(String bpelPackageName) {
    List<String> packageList = findMatchingProcessByPackageName(bpelPackageName);
    if (packageList.size() < 1) {
        log.debug("Handling un-deploy operation on salve (worker) node : package list is empty");
        return -1;
    }
    for (String packageName : packageList) {
        // location for extracted BPEL package
        String bpelPackageLocation = parentProcessStore.getLocalDeploymentUnitRepo().getAbsolutePath() + File.separator + tenantId + File.separator + packageName;
        File bpelPackage = new File(bpelPackageLocation);
        // removing extracted bpel package at repository/bpel/tenantID/
        deleteBpelPackageFromRepo(bpelPackage);
        for (QName pid : getProcessesInPackage(packageName)) {
            ProcessConfigurationImpl processConf = (ProcessConfigurationImpl) getProcessConfiguration(pid);
            // This property is read when we removing the axis service for this process.
            // So that we can decide whether we should persist service QOS configs
            processConf.setUndeploying(true);
        }
    }
    Collection<QName> undeployedProcesses = new ArrayList<QName>();
    for (String nameWithVersion : packageList) {
        undeploySpecificVersionOfBPELPackage(nameWithVersion, undeployedProcesses);
    }
    BPELServerImpl instance = BPELServerImpl.getInstance();
    BpelServerImpl odeBpelServer = instance.getODEBPELServer();
    for (QName pid : undeployedProcesses) {
        odeBpelServer.unregister(pid);
        ProcessConf pConf = parentProcessStore.getProcessConfiguration(pid);
        if (pConf != null) {
            if (log.isDebugEnabled()) {
                log.debug("Cancelling all cron scheduled jobs for process " + pid);
            }
            odeBpelServer.getContexts().cronScheduler.cancelProcessCronJobs(pid, true);
        }
        log.info("Process " + pid + " un-deployed.");
    }
    parentProcessStore.updateProcessAndDUMapsForSalve(tenantId, bpelPackageName, undeployedProcesses);
    return 0;
}
Also used : BpelServerImpl(org.apache.ode.bpel.engine.BpelServerImpl) QName(javax.xml.namespace.QName) BPELServerImpl(org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) ArrayList(java.util.ArrayList) File(java.io.File)

Example 92 with Property

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property in project carbon-business-process by wso2.

the class AbstractPaginateList method paginateList.

public DataResponse paginateList(Map<String, String> requestParams, PaginateRequest paginateRequest, Query query, String defaultSort, Map<String, QueryProperty> properties) {
    if (paginateRequest == null) {
        paginateRequest = new PaginateRequest();
    }
    // In case pagination request is incomplete, fill with values found in URL if possible
    if (paginateRequest.getStart() == null) {
        paginateRequest.setStart(RequestUtil.getInteger(requestParams, "start", 0));
    }
    if (paginateRequest.getSize() == null) {
        paginateRequest.setSize(RequestUtil.getInteger(requestParams, "size", 10));
    }
    if (paginateRequest.getOrder() == null) {
        paginateRequest.setOrder(requestParams.get("order"));
    }
    if (paginateRequest.getSort() == null) {
        paginateRequest.setSort(requestParams.get("sort"));
    }
    // Use defaults for paging, if not set in the PaginationRequest, nor in the URL
    Integer start = paginateRequest.getStart();
    if (start == null || start < 0) {
        start = 0;
    }
    Integer size = paginateRequest.getSize();
    if (size == null || size < 0) {
        size = 10;
    }
    String sort = paginateRequest.getSort();
    if (sort == null) {
        // id
        sort = defaultSort;
    }
    String order = paginateRequest.getOrder();
    if (order == null) {
        order = "asc";
    }
    // Sort order
    if (sort != null && !properties.isEmpty()) {
        QueryProperty qp = properties.get(sort);
        if (qp == null) {
            throw new ActivitiIllegalArgumentException("Value for param 'sort' is not valid, '" + sort + "' is not a valid property");
        }
        ((AbstractQuery) query).orderBy(qp);
        if (order.equals("asc")) {
            query.asc();
        } else if (order.equals("desc")) {
            query.desc();
        } else {
            throw new ActivitiIllegalArgumentException("Value for param 'order' is not valid : '" + order + "', must be 'asc' or 'desc'");
        }
    }
    // Get result and set pagination parameters
    List list = processList(query.listPage(start, size));
    DataResponse response = new DataResponse();
    response.setStart(start);
    response.setSize(list.size());
    response.setSort(sort);
    response.setOrder(order);
    response.setTotal(query.count());
    response.setData(list);
    return response;
}
Also used : DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryProperty(org.activiti.engine.query.QueryProperty) AbstractQuery(org.activiti.engine.impl.AbstractQuery) List(java.util.List)

Example 93 with Property

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property in project carbon-business-process by wso2.

the class SubstitutionDataHolder method isTransitivityEnabled.

/**
 * Get the transitivity enabled value for substitution from configuration.
 * @return true if transitivity enabled
 */
public boolean isTransitivityEnabled() {
    if (transitivityEnabled != null) {
        return transitivityEnabled;
    } else {
        transitivityEnabled = BPMNConstants.SUBSTITUTION_TRANSITIVITY_DEFAULT;
        BPMNActivitiConfiguration bpmnActivitiConfiguration = BPMNActivitiConfiguration.getInstance();
        if (bpmnActivitiConfiguration != null) {
            String transitivityEnabledProperty = bpmnActivitiConfiguration.getBPMNPropertyValue(BPMNConstants.SUBSTITUTION_CONFIG, BPMNConstants.SUBSTITUTION_TRANSITIVITY_PROPERTY);
            if (transitivityEnabledProperty != null) {
                if (transitivityEnabledProperty.trim().equalsIgnoreCase("true") || transitivityEnabledProperty.trim().equalsIgnoreCase("false")) {
                    transitivityEnabled = Boolean.parseBoolean(transitivityEnabledProperty);
                    if (log.isDebugEnabled()) {
                        log.debug("User substitution transitivity enabled : " + transitivityEnabled);
                    }
                } else {
                    log.warn("Invalid value for the property: " + BPMNConstants.SUBSTITUTION_TRANSITIVITY_PROPERTY + ". Transitivity is being disabled by default.");
                }
            }
        }
        return transitivityEnabled;
    }
}
Also used : BPMNActivitiConfiguration(org.wso2.carbon.bpmn.core.utils.BPMNActivitiConfiguration)

Example 94 with Property

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property in project product-iots by wso2.

the class ZipUtil method getSketchArchive.

/**
 * Get agent sketch.
 *
 * @param archivesPath       Path of the zip file to create.
 * @param templateSketchPath Path of the sketch.
 * @param contextParams      Map of parameters to be included in the zip file.
 * @param zipFileName        Name of the zip file.
 * @return Created zip archive.
 * @throws DeviceManagementException
 * @throws IOException
 */
public static ZipArchive getSketchArchive(String archivesPath, String templateSketchPath, Map contextParams, String zipFileName) throws DeviceManagementException, IOException {
    String sketchPath = CarbonUtils.getCarbonHome() + File.separator + templateSketchPath;
    // clear directory
    FileUtils.deleteDirectory(new File(archivesPath));
    // clear zip
    FileUtils.deleteDirectory(new File(archivesPath + ".zip"));
    if (!new File(archivesPath).mkdirs()) {
        // new dir
        String message = "Could not create directory at path: " + archivesPath;
        throw new DeviceManagementException(message);
    }
    zipFileName = zipFileName + ".zip";
    try {
        Map<String, List<String>> properties = getProperties(sketchPath + File.separator + "sketch" + ".properties");
        List<String> templateFiles = properties.get("templates");
        for (String templateFile : templateFiles) {
            parseTemplate(templateSketchPath + File.separator + templateFile, archivesPath + File.separator + templateFile, contextParams);
        }
        // ommit copying the props file
        templateFiles.add("sketch.properties");
        copyFolder(new File(sketchPath), new File(archivesPath), templateFiles);
        createZipArchive(archivesPath);
        FileUtils.deleteDirectory(new File(archivesPath));
        File zip = new File(archivesPath + ".zip");
        return new ZipArchive(zipFileName, zip);
    } catch (IOException ex) {
        throw new DeviceManagementException("Error occurred when trying to read property " + "file sketch.properties", ex);
    }
}
Also used : DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) File(java.io.File)

Example 95 with Property

use of org.wso2.carbon.governance.custom.lifecycles.checklist.util.Property in project carbon-apimgt by wso2.

the class SubscriberInfoLoader method handleThrottle.

private boolean handleThrottle(WebhooksDTO subscriber, MessageContext messageContext) {
    AuthenticationContext authContext = new AuthenticationContext();
    populateAuthContext(subscriber.getTenantDomain(), Integer.parseInt(subscriber.getAppID()), authContext);
    messageContext.setProperty(APISecurityUtils.API_AUTH_CONTEXT, authContext);
    if (subscriber.isThrottled()) {
        if (APIUtil.isAnalyticsEnabled()) {
            String errorMessage = "Message throttled out";
            String errorDescription = "You have exceeded your quota";
            int errorCode = APIThrottleConstants.EVENTS_COUNT_THROTTLE_OUT_ERROR_CODE;
            messageContext.setProperty(SynapseConstants.ERROR_CODE, errorCode);
            messageContext.setProperty(SynapseConstants.ERROR_MESSAGE, errorMessage);
            messageContext.setProperty(SynapseConstants.ERROR_DETAIL, errorDescription);
            messageContext.setProperty(Constants.BACKEND_RESPONSE_CODE, APIThrottleConstants.SC_TOO_MANY_REQUESTS);
            ((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(SynapseConstants.HTTP_SC, APIThrottleConstants.SC_TOO_MANY_REQUESTS);
            WebhooksUtils.publishAnalyticsData(messageContext);
        }
        return false;
    }
    if (doThrottle(subscriber, messageContext, authContext)) {
        messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_CALLBACK_PROPERTY, subscriber.getCallbackURL());
        String errorMessage = "Message throttled out";
        String errorDescription = "You have exceeded your quota";
        int errorCode = APIThrottleConstants.EVENTS_COUNT_THROTTLE_OUT_ERROR_CODE;
        int httpErrorCode = APIThrottleConstants.SC_TOO_MANY_REQUESTS;
        messageContext.setProperty(SynapseConstants.ERROR_CODE, errorCode);
        messageContext.setProperty(SynapseConstants.ERROR_MESSAGE, errorMessage);
        messageContext.setProperty(SynapseConstants.ERROR_DETAIL, errorDescription);
        messageContext.setProperty(APIMgtGatewayConstants.HTTP_RESPONSE_STATUS_CODE, httpErrorCode);
        org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
        // This property need to be set to avoid sending the content in pass-through pipe (request message)
        // as the response.
        axis2MC.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE);
        try {
            RelayUtils.consumeAndDiscardMessage(axis2MC);
        } catch (AxisFault axisFault) {
            // In case of an error it is logged and the process is continued because we're setting a fault message
            // in the payload.
            log.error("Error occurred while consuming and discarding the message", axisFault);
        }
        if (APIUtil.isAnalyticsEnabled()) {
            messageContext.setProperty(Constants.BACKEND_RESPONSE_CODE, httpErrorCode);
            ((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(SynapseConstants.HTTP_SC, APIThrottleConstants.SC_TOO_MANY_REQUESTS);
            WebhooksUtils.publishAnalyticsData(messageContext);
        }
        Mediator sequence = messageContext.getSequence(APIThrottleConstants.API_THROTTLE_OUT_HANDLER);
        // Invoke the custom error handler specified by the user
        if (sequence != null && !sequence.mediate(messageContext)) {
            // logic from getting executed
            return true;
        }
        Utils.sendFault(messageContext, httpErrorCode);
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) AbstractMediator(org.apache.synapse.mediators.AbstractMediator) Mediator(org.apache.synapse.Mediator) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)32 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 Resource (org.wso2.carbon.registry.core.Resource)23 Map (java.util.Map)21 Test (org.junit.Test)21 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)21 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)17 API (org.wso2.carbon.apimgt.api.model.API)16 UserStoreException (org.wso2.carbon.user.api.UserStoreException)16 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 JSONObject (org.json.simple.JSONObject)14 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)14 List (java.util.List)13 IOException (java.io.IOException)11 QName (javax.xml.namespace.QName)11 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)11 Properties (java.util.Properties)10 GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)10