use of org.wso2.carbon.registry.core.Collection in project carbon-business-process by wso2.
the class Instance method getPaginatedInstanceList.
public PaginatedInstanceList getPaginatedInstanceList(String filter, final String order, final int limit, final int page) throws InstanceManagementException {
String tFilter = filter;
final PaginatedInstanceList instanceList = new PaginatedInstanceList();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
TenantProcessStoreImpl tenantProcessStore = (TenantProcessStoreImpl) bpelServer.getMultiTenantProcessStore().getTenantsProcessStore(tenantId);
if (tenantProcessStore.getProcessConfigMap().size() <= 0) {
instanceList.setPages(0);
return instanceList;
}
if (!tFilter.contains(" pid=")) {
tFilter = tFilter + getTenantsProcessList(tenantProcessStore.getProcessConfigMap().keySet());
}
if (log.isDebugEnabled()) {
log.debug("Instance Filter:" + tFilter);
}
final InstanceFilter instanceFilter = new InstanceFilter(tFilter, order, limit);
try {
BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
bpelDb.exec(new BpelDatabase.Callable<Object>() {
public Object run(BpelDAOConnection conn) throws InstanceManagementException {
Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
int pageNum = page;
if (pageNum < 0 || pageNum == Integer.MAX_VALUE) {
pageNum = 0;
}
int startIndexOfCurrentPage = pageNum * BPELConstants.ITEMS_PER_PAGE;
int endIndexOfCurrentPage = (pageNum + 1) * BPELConstants.ITEMS_PER_PAGE;
int instanceListSize = instances.size();
int pages = (int) Math.ceil((double) instanceListSize / BPELConstants.ITEMS_PER_PAGE);
instanceList.setPages(pages);
ProcessInstanceDAO[] instanceArray = instances.toArray(new ProcessInstanceDAO[instanceListSize]);
for (int i = startIndexOfCurrentPage; (i < endIndexOfCurrentPage && i < instanceListSize); i++) {
instanceList.addInstance(createLimitedInstanceInfoObject(instanceArray[i]));
}
return null;
}
});
} catch (Exception e) {
String errMsg = "Error querying instances from database. Instance Filter:" + instanceFilter.toString();
log.error(errMsg, e);
throw new InstanceManagementException(errMsg, e);
}
return instanceList;
}
use of org.wso2.carbon.registry.core.Collection 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;
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class AbstractAPIManager method getApiSpecificMediationResourceFromUuid.
/**
* Returns Registry resource matching given mediation policy identifier
*
* @param identifier API identifier
* @param uuid mediation policy identifier
* @param resourcePath registry path to the API resource
* @return Registry resource matches given identifier or null
* @throws APIManagementException If fails to get the resource matching given identifier
*/
@Override
public Resource getApiSpecificMediationResourceFromUuid(Identifier identifier, String uuid, String resourcePath) throws APIManagementException {
try {
Resource resource = registry.get(resourcePath);
if (resource instanceof Collection) {
Collection typeCollection = (Collection) resource;
String[] typeArray = typeCollection.getChildren();
for (String type : typeArray) {
// Check for mediation policy resource
if ((type.equalsIgnoreCase(resourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN)) || (type.equalsIgnoreCase(resourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT)) || (type.equalsIgnoreCase(resourcePath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT))) {
Resource sequenceType = registry.get(type);
// sequenceType eg: in / out /fault
if (sequenceType instanceof Collection) {
String[] mediationPolicyArr = ((Collection) sequenceType).getChildren();
for (String mediationPolicy : mediationPolicyArr) {
Resource mediationResource = registry.get(mediationPolicy);
String resourceId = mediationResource.getUUID();
if (resourceId.equalsIgnoreCase(uuid)) {
return mediationResource;
}
}
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while obtaining registry objects";
throw new APIManagementException(msg, e);
}
return null;
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class AbstractAPIManager method getWsdlResourceFromUuid.
/**
* Returns the wsdl registry resource correspond to the given identifier
*
* @param wsdlId uuid of the wsdl resource
* @return Registry resource of given identifier or null
* @throws APIManagementException If failed to get the registry resource of given uuid
*/
@Override
public Resource getWsdlResourceFromUuid(String wsdlId) throws APIManagementException {
String resourcePath = APIConstants.API_WSDL_RESOURCE;
try {
if (registry.resourceExists(resourcePath)) {
Resource resource = registry.get(resourcePath);
if (resource instanceof Collection) {
Collection wsdlCollection = (Collection) resource;
String[] wsdlArray = wsdlCollection.getChildren();
for (String wsdl : wsdlArray) {
Resource wsdlResource = registry.get(wsdl);
String resourceId = wsdlResource.getUUID();
if (resourceId.equals(wsdlId)) {
return wsdlResource;
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while accessing registry objects";
throw new APIManagementException(msg, e);
}
return null;
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAllGlobalMediationPolicies.
/**
* Returns list of global mediation policies available
*
* @return List of Mediation objects of global mediation policies
* @throws APIManagementException If failed to get global mediation policies
*/
@Override
public List<Mediation> getAllGlobalMediationPolicies() throws APIManagementException {
List<Mediation> mediationList = new ArrayList<Mediation>();
Mediation mediation;
String resourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
try {
// Resource : customsequences
Resource resource = registry.get(resourcePath);
if (resource instanceof Collection) {
Collection typeCollection = (Collection) resource;
String[] typeArray = typeCollection.getChildren();
for (String type : typeArray) {
// Resource : in / out / fault
Resource typeResource = registry.get(type);
if (typeResource instanceof Collection) {
String[] sequenceArray = ((Collection) typeResource).getChildren();
if (sequenceArray.length > 0) {
for (String sequence : sequenceArray) {
// Resource : actual resource eg : log_in_msg.xml
Resource sequenceResource = registry.get(sequence);
String resourceId = sequenceResource.getUUID();
try {
String contentString = IOUtils.toString(sequenceResource.getContentStream(), RegistryConstants.DEFAULT_CHARSET_ENCODING);
OMElement omElement = AXIOMUtil.stringToOM(contentString);
OMAttribute attribute = omElement.getAttribute(new QName(PolicyConstants.MEDIATION_NAME_ATTRIBUTE));
String mediationPolicyName = attribute.getAttributeValue();
mediation = new Mediation();
mediation.setUuid(resourceId);
mediation.setName(mediationPolicyName);
// Extract sequence type from the registry resource path
String resourceType = type.substring(type.lastIndexOf("/") + 1);
mediation.setType(resourceType);
// Add mediation to the mediation list
mediationList.add(mediation);
} catch (XMLStreamException e) {
// If any exception been caught flow may continue with the next mediation policy
log.error("Error occurred while getting omElement out of " + "mediation content from " + sequence, e);
} catch (IOException e) {
log.error("Error occurred while converting resource " + "contentStream in to string in " + sequence, e);
}
}
}
}
}
}
} catch (RegistryException e) {
String msg = "Failed to get global mediation policies";
throw new APIManagementException(msg, e);
}
return mediationList;
}
Aggregations