public String promoteService(String version, String currentPath, String promoteStatus) throws CustomLifecyclesChecklistAdminServiceExceptionException, RemoteException, RegistryException { ArrayOfString[] parameters = new ArrayOfString[2]; String[] dependencyList = lifeCycleAdminServiceClient.getAllDependencies(currentPath); parameters[0] = new ArrayOfString(); parameters[0].setArray(new String[] {dependencyList[0], version}); parameters[1] = new ArrayOfString(); parameters[1].setArray(new String[] {"preserveOriginal", "false"}); String ACTION_PROMOTE = "Promote"; String ASPECT_NAME = "DiffEnvironmentLC"; lifeCycleAdminServiceClient.invokeAspectWithParams( currentPath, ASPECT_NAME, ACTION_PROMOTE, null, parameters); String newPath = "/_system/governance/branches/" + promoteStatus + "/services/" + NAMESPACE + "/" + version + "/" + SERVICE_NAME; Resource service = wsRegistryServiceClient.get(newPath); Assert.assertNotNull(service, "Service Not found on registry path " + newPath); Assert.assertEquals(service.getPath(), newPath, "Service not in branches/testing. " + newPath); return newPath; }
/** * Cleanup the used resources * * @param tenantLessUserName, userName without tenant * @param domain, The tenant domain * @throws AdminManagementException, if the cleanup failed. */ public static void cleanupResources(String tenantLessUserName, String domain) throws AdminManagementException { String adminManagementPath = getAdminManagementPath(tenantLessUserName, domain); UserRegistry superTenantSystemRegistry; Resource resource; try { superTenantSystemRegistry = AdminManagementServiceComponent.getGovernanceSystemRegistry( MultitenantConstants.SUPER_TENANT_ID); if (superTenantSystemRegistry.resourceExists(adminManagementPath)) { resource = superTenantSystemRegistry.get(adminManagementPath); Resource tempResource = superTenantSystemRegistry.get(resource.getPath()); if (tempResource != null) { superTenantSystemRegistry.delete(resource.getPath()); } } } catch (RegistryException e) { String msg = "Registry resource doesn't exist at the path, " + adminManagementPath; log.error(msg, e); throw new AdminManagementException(msg, e); } }
public void invoke(RequestContext context, String action) throws RegistryException { if (!ACTION.equals(action)) { throw new RegistryException("Wrong action"); } Resource r = context.getResource(); String state = r.getProperty(STATE_PROP); if (state == null) { throw new RegistryException("No state property"); } if (!INIT.equals(state)) { throw new RegistryException("Invalid state '" + state + "'"); } r.setProperty(STATE_PROP, FINAL); context.getRegistry().put(r.getPath(), r); }
public String addWadlToRegistry( RequestContext requestContext, Resource resource, String resourcePath, boolean skipValidation) throws RegistryException { String wadlName = RegistryUtils.getResourceName(resourcePath); String version = requestContext.getResource().getProperty(RegistryConstants.VERSION_PARAMETER_NAME); if (version == null) { version = CommonConstants.WADL_VERSION_DEFAULT_VALUE; requestContext.getResource().setProperty(RegistryConstants.VERSION_PARAMETER_NAME, version); } OMElement wadlElement; String wadlContent; Object resourceContent = resource.getContent(); if (resourceContent instanceof String) { wadlContent = (String) resourceContent; } else { wadlContent = new String((byte[]) resourceContent); } try { XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(wadlContent)); StAXOMBuilder builder = new StAXOMBuilder(reader); wadlElement = builder.getDocumentElement(); } catch (XMLStreamException e) { // This exception is unexpected because the WADL already validated String msg = "Unexpected error occured " + "while reading the WADL at " + resourcePath + "."; log.error(msg); throw new RegistryException(msg, e); } String wadlNamespace = wadlElement.getNamespace().getNamespaceURI(); String namespaceSegment = CommonUtil.derivePathFragmentFromNamespace(wadlNamespace).replace("//", "/"); String actualPath = getChrootedWadlLocation(requestContext.getRegistryContext()) + namespaceSegment + version + "/" + wadlName; OMElement grammarsElement = wadlElement.getFirstChildWithName(new QName(wadlNamespace, "grammars")); if (StringUtils.isNotBlank(requestContext.getSourceURL())) { String uri = requestContext.getSourceURL(); if (!skipValidation) { validateWADL(uri); } if (resource.getUUID() == null) { resource.setUUID(UUID.randomUUID().toString()); } String wadlBaseUri = uri.substring(0, uri.lastIndexOf("/") + 1); if (grammarsElement != null) { // This is to avoid evaluating the grammars import when building AST grammarsElement.detach(); wadlElement.addChild(resolveImports(grammarsElement, wadlBaseUri, version)); } } else { if (!skipValidation) { File tempFile = null; BufferedWriter bufferedWriter = null; try { tempFile = File.createTempFile(wadlName, null); bufferedWriter = new BufferedWriter(new FileWriter(tempFile)); bufferedWriter.write(wadlElement.toString()); bufferedWriter.flush(); } catch (IOException e) { String msg = "Error occurred while reading the WADL File"; log.error(msg, e); throw new RegistryException(msg, e); } finally { if (bufferedWriter != null) { try { bufferedWriter.close(); } catch (IOException e) { String msg = "Error occurred while closing File writer"; log.warn(msg, e); } } } validateWADL(tempFile.toURI().toString()); try { delete(tempFile); } catch (IOException e) { String msg = "An error occurred while deleting the temporary files from local file system."; log.warn(msg, e); throw new RegistryException(msg, e); } } if (grammarsElement != null) { grammarsElement = resolveImports(grammarsElement, null, version); wadlElement.addChild(grammarsElement); } } requestContext.setResourcePath(new ResourcePath(actualPath)); if (resource.getProperty(CommonConstants.SOURCE_PROPERTY) == null) { resource.setProperty(CommonConstants.SOURCE_PROPERTY, CommonConstants.SOURCE_AUTO); } registry.put(actualPath, resource); addImportAssociations(actualPath); if (getCreateService()) { OMElement serviceElement = RESTServiceUtils.createRestServiceArtifact( wadlElement, wadlName, version, RegistryUtils.getRelativePath(requestContext.getRegistryContext(), actualPath)); String servicePath = RESTServiceUtils.addServiceToRegistry(requestContext, serviceElement); registry.addAssociation(servicePath, actualPath, CommonConstants.DEPENDS); registry.addAssociation(actualPath, servicePath, CommonConstants.USED_BY); String endpointPath = createEndpointElement(requestContext, wadlElement, version); if (endpointPath != null) { registry.addAssociation(servicePath, endpointPath, CommonConstants.DEPENDS); registry.addAssociation(endpointPath, servicePath, CommonConstants.USED_BY); } } return resource.getPath(); }