Search in sources :

Example 21 with LOCAL

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-apimgt by wso2.

the class InMemoryAPIDeployer method cleanDeployment.

public void cleanDeployment(String artifactRepositoryPath) {
    File artifactRepoPath = Paths.get(artifactRepositoryPath, SynapseConstants.SYNAPSE_CONFIGS, SynapseConstants.DEFAULT_DIR).toFile();
    if (artifactRepoPath.exists() && artifactRepoPath.isDirectory()) {
        GatewayCleanupSkipList gatewayCleanupSkipList = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration().getGatewayCleanupSkipList();
        File apiPath = Paths.get(artifactRepoPath.getAbsolutePath(), "api").toFile();
        if (apiPath.exists() && apiPath.isDirectory()) {
            clean(apiPath, gatewayCleanupSkipList.getApis());
        }
        File localEntryPath = Paths.get(artifactRepoPath.getAbsolutePath(), "local-entries").toFile();
        if (localEntryPath.exists() && localEntryPath.isDirectory()) {
            clean(localEntryPath, gatewayCleanupSkipList.getLocalEntries());
        }
        File endpointPath = Paths.get(artifactRepoPath.getAbsolutePath(), "endpoints").toFile();
        if (endpointPath.exists() && endpointPath.isDirectory()) {
            clean(endpointPath, gatewayCleanupSkipList.getEndpoints());
        }
        File sequencesPath = Paths.get(artifactRepoPath.getAbsolutePath(), "sequences").toFile();
        if (sequencesPath.exists() && sequencesPath.isDirectory()) {
            clean(sequencesPath, gatewayCleanupSkipList.getSequences());
        }
    }
}
Also used : GatewayCleanupSkipList(org.wso2.carbon.apimgt.impl.dto.GatewayCleanupSkipList) File(java.io.File)

Example 22 with LOCAL

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-apimgt by wso2.

the class APIProviderImpl method updateAPIResources.

/**
 * Update resources of the API including local scopes and resource to scope attachments.
 *
 * @param api      API
 * @param tenantId Tenant Id
 * @throws APIManagementException If fails to update local scopes of the API.
 */
private void updateAPIResources(API api, int tenantId) throws APIManagementException {
    String tenantDomain = APIUtil.getTenantDomainFromTenantId(tenantId);
    APIIdentifier apiIdentifier = api.getId();
    // Get the new URI templates for the API
    Set<URITemplate> uriTemplates = api.getUriTemplates();
    // Get the existing local scope keys attached for the API
    Set<String> oldLocalScopeKeys = apiMgtDAO.getAllLocalScopeKeysForAPI(api.getUuid(), tenantId);
    // Get the existing URI templates for the API
    Set<URITemplate> oldURITemplates = apiMgtDAO.getURITemplatesOfAPI(api.getUuid());
    // Get the new local scope keys from URI templates
    Set<Scope> newLocalScopes = getScopesToRegisterFromURITemplates(api.getId().getApiName(), api.getOrganization(), uriTemplates);
    Set<String> newLocalScopeKeys = newLocalScopes.stream().map(Scope::getKey).collect(Collectors.toSet());
    // Get the existing versioned local scope keys attached for the API
    Set<String> oldVersionedLocalScopeKeys = apiMgtDAO.getVersionedLocalScopeKeysForAPI(api.getUuid(), tenantId);
    // Get the existing versioned local scope keys which needs to be removed (not updated) from the current updating
    // API and remove them from the oldLocalScopeKeys set before sending to KM, so that they will not be removed
    // from KM and can be still used by other versioned APIs.
    Iterator oldLocalScopesItr = oldLocalScopeKeys.iterator();
    while (oldLocalScopesItr.hasNext()) {
        String oldLocalScopeKey = (String) oldLocalScopesItr.next();
        // if the scope is used in versioned APIs and it is not in new local scope key set
        if (oldVersionedLocalScopeKeys.contains(oldLocalScopeKey) && !newLocalScopeKeys.contains(oldLocalScopeKey)) {
            // remove from old local scope key set which will be send to KM
            oldLocalScopesItr.remove();
        }
    }
    apiMgtDAO.updateURITemplates(api, tenantId);
    if (log.isDebugEnabled()) {
        log.debug("Successfully updated the URI templates of API: " + apiIdentifier + " in the database");
    }
    // Update the resource scopes of the API in KM.
    // Need to remove the old local scopes and register new local scopes and, update the resource scope mappings
    // using the updated URI templates of the API.
    deleteScopes(oldLocalScopeKeys, tenantId);
    addScopes(newLocalScopes, tenantId);
    Map<String, KeyManagerDto> tenantKeyManagers = KeyManagerHolder.getTenantKeyManagers(tenantDomain);
    for (Map.Entry<String, KeyManagerDto> keyManagerDtoEntry : tenantKeyManagers.entrySet()) {
        KeyManager keyManager = keyManagerDtoEntry.getValue().getKeyManager();
        if (keyManager != null) {
            try {
                keyManager.updateResourceScopes(api, oldLocalScopeKeys, newLocalScopes, oldURITemplates, uriTemplates);
                if (log.isDebugEnabled()) {
                    log.debug("Successfully updated the resource scopes of API: " + apiIdentifier + " in Key Manager " + keyManagerDtoEntry.getKey() + " .");
                }
            } catch (APIManagementException e) {
                log.error("Error while updating resource to scope attachment in Key Manager " + keyManagerDtoEntry.getKey(), e);
            }
        }
    }
}
Also used : URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) Scope(org.wso2.carbon.apimgt.api.model.Scope) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Iterator(java.util.Iterator) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager)

Example 23 with LOCAL

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project siddhi by wso2.

the class PartitionStreamReceiver method addStreamJunction.

/**
 * create local streamJunctions through which events received by partitionStreamReceiver, are sent to
 * queryStreamReceivers
 *
 * @param key              partitioning key
 * @param queryRuntimeList queryRuntime list of the partition
 */
public void addStreamJunction(String key, List<QueryRuntime> queryRuntimeList) {
    StreamJunction streamJunction = cachedStreamJunctionMap.get(streamId + key);
    if (streamJunction == null) {
        streamJunction = partitionRuntime.getLocalStreamJunctionMap().get(streamId + key);
        if (streamJunction == null) {
            streamJunction = createStreamJunction();
            partitionRuntime.addStreamJunction(streamId + key, streamJunction);
        }
        cachedStreamJunctionMap.put(streamId + key, streamJunction);
    }
    for (QueryRuntime queryRuntime : queryRuntimeList) {
        StreamRuntime streamRuntime = queryRuntime.getStreamRuntime();
        for (int i = 0; i < queryRuntime.getInputStreamId().size(); i++) {
            if ((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver().getStreamId().equals(streamId + key)) {
                streamJunction.subscribe((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver());
            }
        }
    }
}
Also used : QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime)

Example 24 with LOCAL

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-business-process by wso2.

the class AttachmentMgtDAOConnectionFactoryImpl method init.

@Override
public void init() {
    if (transactionManager == null) {
        log.debug("Transaction-Manager is not initialized before initializing entityManager. So internal " + "transaction-manager in entity manager will be used.");
    }
    JPAVendorAdapter vendorAdapter = getJPAVendorAdapter();
    // Here we pass a "null" valued transaction manager,
    // as we enforce the entity-manager-factory to use its local transactions. In future,
    // if required to use external JTA transactions, a transaction reference should be passed
    // as the input parameter.
    this.entityManagerFactory = Persistence.createEntityManagerFactory("Attachment-Mgt-PU", vendorAdapter.getJpaPropertyMap(null));
}
Also used : JPAVendorAdapter(org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.JPAVendorAdapter)

Example 25 with LOCAL

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL in project carbon-business-process by wso2.

the class HistoricTaskInstanceService method getVariableFromRequest.

protected RestVariable getVariableFromRequest(boolean includeBinary, String taskId, String variableName, String scope) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskId(taskId);
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            taskQuery.includeProcessVariables();
        } else {
            taskQuery.includeTaskLocalVariables();
        }
    } else {
        taskQuery.includeTaskLocalVariables().includeProcessVariables();
    }
    HistoricTaskInstance taskObject = taskQuery.singleResult();
    if (taskObject == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' couldn't be found.", HistoricTaskInstanceEntity.class);
    }
    Object value = null;
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            value = taskObject.getProcessVariables().get(variableName);
        } else {
            value = taskObject.getTaskLocalVariables().get(variableName);
        }
    } else {
        // look for local task restVariables first
        if (taskObject.getTaskLocalVariables().containsKey(variableName)) {
            value = taskObject.getTaskLocalVariables().get(variableName);
        } else {
            value = taskObject.getProcessVariables().get(variableName);
        }
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableName, value, null, taskId, RestResponseFactory.VARIABLE_HISTORY_TASK, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Aggregations

RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)14 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)12 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 Map (java.util.Map)6 HashMap (java.util.HashMap)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 RuntimeService (org.activiti.engine.RuntimeService)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 TreeMap (java.util.TreeMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Response (javax.ws.rs.core.Response)3 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)3 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)3 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3