Search in sources :

Example 6 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-business-process by wso2.

the class HumanTaskAppDeployer method undeployArtifacts.

/**
 * Check the artifact type and if it is a HumanTask, delete the file from the HumanTask
 * deployment hot folder
 *
 * @param carbonApp  - CarbonApplication instance to check for HumanTask artifacts
 * @param axisConfig - - axisConfig of the current tenant
 */
public void undeployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) {
    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 (HUMANTASK_TYPE.equals(artifact.getType())) {
            deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, HUMANTASK_DIR, "zip");
        } else {
            continue;
        }
        List<CappFile> files = artifact.getFiles();
        if (files.size() != 1) {
            log.error("A HumanTask artifact 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 {
                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) Artifact(org.wso2.carbon.application.deployer.config.Artifact) Deployer(org.apache.axis2.deployment.Deployer) CappFile(org.wso2.carbon.application.deployer.config.CappFile)

Example 7 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method isOperationIsValidForTheCurrentTenant.

/**
 * Check whether the instance belongs to the current tenant. If not, don't allow any operations.
 *
 * @param iid instance id
 * @throws IllegalAccessException if instance doesn't belong to the current tenant
 * @throws ProcessingException    if there a error getting instance data
 * @throws InstanceManagementException if the processId does not exist
 */
private void isOperationIsValidForTheCurrentTenant(final long iid) throws IllegalAccessException, ProcessingException, InstanceManagementException {
    QName processId = getProcess(iid);
    TenantProcessStoreImpl processStore = getTenantProcessForCurrentSession();
    if (processId != null) {
        if (!processStore.containsProcess(processId)) {
            log.error("Trying to invoke a illegal operation. Instance ID:" + iid);
            throw new IllegalAccessException("Operation is not permitted.");
        }
    } else {
        throw new InstanceManagementException("Process instance for instance ID " + iid + " does not exist");
    }
}
Also used : InstanceManagementException(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException) QName(javax.xml.namespace.QName) TenantProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStoreImpl)

Example 8 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-business-process by wso2.

the class TenantProcessStoreImpl method init.

public void init() throws Exception {
    bpelDURepo = new File(parentProcessStore.getLocalDeploymentUnitRepo(), tenantId.toString());
    if (!bpelDURepo.exists() && !bpelDURepo.mkdirs()) {
        log.warn("Cannot create tenant " + tenantId + " BPEL deployment unit repository.");
    }
    repository = new BPELPackageRepository(tenantConfigRegistry, bpelDURepo, bpelArchiveRepo);
    repository.init();
}
Also used : BPELPackageRepository(org.wso2.carbon.bpel.core.ode.integration.store.repository.BPELPackageRepository) File(java.io.File)

Example 9 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-business-process by wso2.

the class TenantProcessStoreImpl method findBPELPackageInFileSystem.

private File findBPELPackageInFileSystem(DeploymentUnitDAO dudao) {
    String duName = dudao.getName();
    // Done: Fix the logic to handle registry
    log.info("Looking for BPEL package in file system for deployment unit " + duName);
    File bpelDUDirectory = new File(bpelDURepo, duName);
    if (bpelDUDirectory.exists()) {
        return bpelDUDirectory;
    } else {
        String registryCollectionPath = dudao.getDeploymentUnitDir();
        try {
            if (tenantConfigRegistry.resourceExists(registryCollectionPath)) {
                if (!bpelDUDirectory.exists() && !bpelDUDirectory.mkdirs()) {
                    String errMsg = "Error creating BPEL deployment unit repository for " + "tenant " + tenantId;
                    log.error(errMsg);
                    log.error("Failed to load BPEL deployment unit " + duName + " due to above error.");
                    throw new BPELDeploymentException(errMsg);
                }
                boolean deployedOnCarbon310 = false;
                // Check whether the registry repo is of type carbon 3.1.0
                if (tenantConfigRegistry.resourceExists(registryCollectionPath + RegistryConstants.PATH_SEPARATOR + duName)) {
                    registryCollectionPath += RegistryConstants.PATH_SEPARATOR + duName;
                    deployedOnCarbon310 = true;
                    if (log.isDebugEnabled()) {
                        log.debug("Found a carbon 3.1.0 compatible deployment unit at " + registryCollectionPath);
                    }
                }
                RegistryClientUtils.exportFromRegistry(bpelDUDirectory, registryCollectionPath, tenantConfigRegistry);
                if (deployedOnCarbon310) {
                    if (log.isDebugEnabled()) {
                        log.debug("Recompiling the carbon 3.1.0 compatible deployment unit at " + bpelDUDirectory);
                    }
                    // Re-compiling to get rid of binary compatibility issues.
                    DeploymentUnitDir du = new DeploymentUnitDir(bpelDUDirectory);
                    for (File file : du.allFiles()) {
                        if (file.getAbsolutePath().endsWith(".cbp") && !file.delete()) {
                            log.warn("Unable to delete " + file);
                        }
                    }
                    du.compile();
                }
                return bpelDUDirectory;
            } else {
                String errMsg = "Expected resource: " + registryCollectionPath + " not found in the registry";
                log.error(errMsg);
                throw new BPELDeploymentException(errMsg);
            }
        } catch (RegistryException re) {
            String errMsg = "Error while exporting deployment unit: " + duName + " to file system from the registry.";
            log.error(errMsg, re);
            throw new BPELDeploymentException(errMsg, re);
        }
    }
}
Also used : DeploymentUnitDir(org.apache.ode.store.DeploymentUnitDir) File(java.io.File) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 10 with Tenant

use of org.wso2.carbon.user.api.Tenant in project carbon-business-process by wso2.

the class BPELProcessStateChangedCommand method execute.

@Override
public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
    if (log.isDebugEnabled()) {
        log.debug("New state changed command received. Process: " + pid + " New state: " + processState + " Tenant: " + tenantId);
    }
    ProcessStoreImpl parentProcessStore = (ProcessStoreImpl) configurationContext.getAxisConfiguration().getParameter(BPELConstants.PARAM_PARENT_PROCESS_STORE).getValue();
    TenantProcessStore tenantProcessStore = parentProcessStore.getTenantsProcessStore(tenantId);
    tenantProcessStore.handleBPELProcessStateChangedNotification(pid, processState);
}
Also used : ProcessStoreImpl(org.wso2.carbon.bpel.core.ode.integration.store.ProcessStoreImpl) TenantProcessStore(org.wso2.carbon.bpel.core.ode.integration.store.TenantProcessStore)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)180 UserStoreException (org.wso2.carbon.user.api.UserStoreException)88 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)83 ArrayList (java.util.ArrayList)79 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)70 PreparedStatement (java.sql.PreparedStatement)51 SQLException (java.sql.SQLException)50 IOException (java.io.IOException)49 Connection (java.sql.Connection)49 HashMap (java.util.HashMap)44 ResultSet (java.sql.ResultSet)43 JSONObject (org.json.simple.JSONObject)41 Resource (org.wso2.carbon.registry.core.Resource)40 Registry (org.wso2.carbon.registry.core.Registry)38 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)34 API (org.wso2.carbon.apimgt.api.model.API)34 Test (org.junit.Test)33 File (java.io.File)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)30