Java Code Examples for org.wso2.carbon.apimgt.api.model.APIIdentifier#getApiName()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.APIIdentifier#getApiName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsPerAPISequenceSequenceMissing() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR; PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Mockito.when(registry.resourceExists(eq(path))).thenReturn(true); Mockito.when(registry.get(eq(path))).thenReturn(null); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertFalse(isPerAPiSequence); }
Example 2
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * get the thumbnailLastUpdatedTime for a thumbnail for a given api * * @param apiIdentifier * @return * @throws APIManagementException */ @Override public String getThumbnailLastUpdatedTime(APIIdentifier apiIdentifier) throws APIManagementException { String artifactPath = APIConstants.API_IMAGE_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String thumbPath = artifactPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_ICON_IMAGE; try { if (registry.resourceExists(thumbPath)) { Resource res = registry.get(thumbPath); Date lastModifiedTime = res.getLastModified(); return lastModifiedTime == null ? String.valueOf(res.getCreatedTime().getTime()) : String.valueOf(lastModifiedTime.getTime()); } } catch (RegistryException e) { String msg = "Error while loading API icon from the registry"; throw new APIManagementException(msg, e); } return null; }
Example 3
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsPerAPISequenceResourceMissing() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR; PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Mockito.when(registry.resourceExists(eq(path))).thenReturn(false); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertFalse(isPerAPiSequence); }
Example 4
Source File: APIImportUtil.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method adds Swagger API definition to registry. * * @param apiId Identifier of the imported API * @param swaggerContent Content of Swagger file * @throws APIImportExportException if there is an error occurs when adding Swagger definition */ private static void addSwaggerDefinition(APIIdentifier apiId, String swaggerContent, APIProvider apiProvider) throws APIImportExportException { try { apiProvider.saveSwagger20Definition(apiId, swaggerContent); } catch (APIManagementException e) { String errorMessage = "Error in adding Swagger definition for the API: " + apiId.getApiName() + StringUtils.SPACE + APIConstants.API_DATA_VERSION + ": " + apiId.getVersion(); throw new APIImportExportException(errorMessage, e); } }
Example 5
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomSequenceNull() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(null, null); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "custom", apiIdentifier); Assert.assertNull(customSequence); sampleSequence.close(); }
Example 6
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomSequenceNotFound() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(null, collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "custom", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }
Example 7
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomOutSequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "out" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "out", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }
Example 8
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomInSequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "in", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }
Example 9
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testIsPerAPISequenceNoPathsInCollection() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR; PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Mockito.when(registry.resourceExists(eq(path))).thenReturn(false); Collection collection = Mockito.mock(Collection.class); Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {}; Mockito.when(collection.getChildren()).thenReturn(childPaths); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertFalse(isPerAPiSequence); }
Example 10
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testIsPerAPISequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR; PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Mockito.when(registry.resourceExists(eq(path))).thenReturn(true); Collection collection = Mockito.mock(Collection.class); Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in"); Assert.assertTrue(isPerAPiSequence); }
Example 11
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetMediationSequenceUuidCustomSequenceNotFound() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(null, collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "custom", apiIdentifier); Assert.assertEquals(expectedUUID, actualUUID); sampleSequence.close(); }
Example 12
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetMediationSequenceUuidCustomSequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "custom", apiIdentifier); Assert.assertEquals(expectedUUID, actualUUID); sampleSequence.close(); }
Example 13
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public boolean isAPIAvailable(APIIdentifier identifier) throws APIManagementException { String path = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion(); try { return registry.resourceExists(path); } catch (RegistryException e) { String msg = "Failed to check availability of api :" + path; throw new APIManagementException(msg, e); } }
Example 14
Source File: K8sManager.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Deletes the API from all the clusters it had been deployed * * @param apiId API Identifier * @param containerMgtInfoDetails Clusters which the API has published */ @Override public void deleteAPI(APIIdentifier apiId, JSONObject containerMgtInfoDetails) { String apiName = apiId.getApiName(); JSONObject propreties = (JSONObject) containerMgtInfoDetails.get(PROPERTIES); if (propreties.get(MASTER_URL) != null && propreties.get(SATOKEN) != null && propreties.get(NAMESPACE) != null) { Config config = new ConfigBuilder() .withMasterUrl(propreties.get(MASTER_URL).toString().replace("\\", "")) .withOauthToken(propreties.get(SATOKEN).toString()) .withNamespace(propreties.get(NAMESPACE).toString()) .withClientKeyPassphrase(System.getProperty(CLIENT_KEY_PASSPHRASE)).build(); OpenShiftClient client = new DefaultOpenShiftClient(config); CustomResourceDefinition apiCRD = client.customResourceDefinitions().withName(API_CRD_NAME).get(); NonNamespaceOperation<APICustomResourceDefinition, APICustomResourceDefinitionList, DoneableAPICustomResourceDefinition, Resource<APICustomResourceDefinition, DoneableAPICustomResourceDefinition>> crdClient = getCRDClient(client, apiCRD); crdClient.withName(apiName.toLowerCase()).cascading(true).delete(); log.info("Successfully deleted the [API] " + apiName); } else { log.error("Error occurred while deleting API from Kubernetes cluster"); } }
Example 15
Source File: APIImportUtil.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method adds API sequences to the imported API. If the sequence is a newly defined one, it is added. * * @param pathToArchive location of the extracted folder of the API */ private static void addSOAPToREST(String pathToArchive, API importedApi, Registry registry) throws APIImportExportException { String inFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + IN; String outFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + OUT; //Adding in-sequence, if any if (CommonUtil.checkFileExistence(inFlowFileLocation)) { APIIdentifier apiId = importedApi.getId(); String soapToRestLocationIn = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_IN_RESOURCE; String soapToRestLocationOut = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_OUT_RESOURCE; try { // Import inflow mediation logic Path inFlowDirectory = Paths.get(inFlowFileLocation); ImportMediationLogic(inFlowDirectory, registry, soapToRestLocationIn); // Import outflow mediation logic Path outFlowDirectory = Paths.get(outFlowFileLocation); ImportMediationLogic(outFlowDirectory, registry, soapToRestLocationOut); } catch (DirectoryIteratorException e) { throw new APIImportExportException("Error in importing SOAP to REST mediation logic", e); } } }
Example 16
Source File: APIExportUtil.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Retrieve API Specific sequence details from the registry. * * @param sequenceName Name of the sequence * @param type Sequence type * @param registry Current tenant registry * @return Registry resource name of the sequence and its content * @throws APIImportExportException If an error occurs while retrieving registry elements */ private static AbstractMap.SimpleEntry<String, OMElement> getAPISpecificSequence(APIIdentifier api, String sequenceName, String type, Registry registry) throws APIImportExportException { String regPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + api.getProviderName() + RegistryConstants.PATH_SEPARATOR + api.getApiName() + RegistryConstants.PATH_SEPARATOR + api.getVersion() + RegistryConstants.PATH_SEPARATOR + type; return getSeqDetailsFromRegistry(sequenceName, regPath, registry); }
Example 17
Source File: K8sManager.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Represents the LC change Blocked --> Republish * Redeploy the API CR with "override : false" * * @param apiId API Identifier * @param containerMgtInfoDetails Clusters which the API has published * @param configMapName Name of the Config Map */ @Override public void changeLCStateBlockedToRepublished(APIIdentifier apiId, JSONObject containerMgtInfoDetails, String[] configMapName) { String apiName = apiId.getApiName(); JSONObject propreties = (JSONObject) containerMgtInfoDetails.get(ContainerBasedConstants.PROPERTIES); if (propreties.get(MASTER_URL) != null && propreties.get(SATOKEN) != null && propreties.get(NAMESPACE) != null) { Config config = new ConfigBuilder() .withMasterUrl(propreties.get(MASTER_URL).toString().replace("\\", "")) .withOauthToken(propreties.get(SATOKEN).toString()) .withNamespace(propreties.get(NAMESPACE).toString()) .withClientKeyPassphrase(System.getProperty(CLIENT_KEY_PASSPHRASE)).build(); OpenShiftClient client = new DefaultOpenShiftClient(config); applyAPICustomResourceDefinition(client, configMapName, Integer.parseInt(propreties.get(REPLICAS).toString()) , apiId, false); CustomResourceDefinition crd = client.customResourceDefinitions().withName(API_CRD_NAME).get(); NonNamespaceOperation<APICustomResourceDefinition, APICustomResourceDefinitionList, DoneableAPICustomResourceDefinition, Resource<APICustomResourceDefinition, DoneableAPICustomResourceDefinition>> crdClient = getCRDClient(client, crd); List<APICustomResourceDefinition> apiCustomResourceDefinitionList = crdClient.list().getItems(); for (APICustomResourceDefinition apiCustomResourceDefinition : apiCustomResourceDefinitionList) { if (apiCustomResourceDefinition.getMetadata().getName().equals(apiName.toLowerCase())) { apiCustomResourceDefinition.getSpec().setOverride(false); crdClient.createOrReplace(apiCustomResourceDefinition); log.info("Successfully Re-Published the [API] " + apiName); return; } } log.error("The requested custom resource for the [API] " + apiName + " was not found"); } else { log.error("Error occurred while re-publishing the API in Kubernetes cluster"); } }
Example 18
Source File: K8sManager.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Re-deploy an API * * @param apiId API Identifier * @param containerMgtInfoDetails Clusters which the API has published */ @Override public void apiRepublish(API api, APIIdentifier apiId, Registry registry, JSONObject containerMgtInfoDetails) throws ParseException, APIManagementException { String apiName = apiId.getApiName(); JSONObject propreties = (JSONObject) containerMgtInfoDetails.get(PROPERTIES); String jwtSecurity =""; String basicSecurity = ""; String oauthSecurity = ""; if (propreties.get(MASTER_URL) != null && propreties.get(SATOKEN) != null && propreties.get(NAMESPACE) != null) { Config config = new ConfigBuilder() .withMasterUrl(propreties.get(MASTER_URL).toString().replace("\\", "")) .withOauthToken(propreties.get(SATOKEN).toString()) .withNamespace(propreties.get(NAMESPACE).toString()) .withClientKeyPassphrase(System.getProperty(CLIENT_KEY_PASSPHRASE)).build(); OpenShiftClient client = new DefaultOpenShiftClient(config); if(propreties.get(JWT_SECURITY_CR_NAME) != null){ jwtSecurity = propreties.get(JWT_SECURITY_CR_NAME).toString(); } if(propreties.get(OAUTH2_SECURITY_CR_NAME) != null){ oauthSecurity = propreties.get(OAUTH2_SECURITY_CR_NAME).toString(); } if(propreties.get(BASICAUTH_SECURITY_CR_NAME) != null){ basicSecurity = propreties.get(BASICAUTH_SECURITY_CR_NAME).toString(); } String[] configMapNames = deployConfigMap(api, apiId, registry, client, jwtSecurity, oauthSecurity, basicSecurity, true); CustomResourceDefinition crd = client.customResourceDefinitions().withName(API_CRD_NAME).get(); NonNamespaceOperation<APICustomResourceDefinition, APICustomResourceDefinitionList, DoneableAPICustomResourceDefinition, Resource<APICustomResourceDefinition, DoneableAPICustomResourceDefinition>> crdClient = getCRDClient(client, crd); APICustomResourceDefinition apiCustomResourceDefinition = crdClient.withName(apiName.toLowerCase()).get(); apiCustomResourceDefinition.getSpec().setUpdateTimeStamp(getTimeStamp()); apiCustomResourceDefinition.getSpec().getDefinition().setSwaggerConfigmapNames(configMapNames); //update with interceptors Interceptors interceptors = new Interceptors(); interceptors.setBallerina(new String[]{}); interceptors.setJava(new String[]{}); apiCustomResourceDefinition.getSpec().getDefinition().setInterceptors(interceptors); crdClient.createOrReplace(apiCustomResourceDefinition); log.info("Successfully Re-deployed the [API] " + apiName); } else { log.error("Error occurred while re-deploying the API in Kubernetes cluster"); } }
Example 19
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testGetAllApiSpecificMediationPolicies() throws RegistryException, APIManagementException, IOException, XMLStreamException { APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION); String parentCollectionPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + APIConstants.API_RESOURCE_NAME; parentCollectionPath = parentCollectionPath.substring(0, parentCollectionPath.lastIndexOf("/")); Collection parentCollection = new CollectionImpl(); parentCollection.setChildren(new String[] { parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT }); Collection childCollection = new CollectionImpl(); childCollection.setChildren(new String[] { "mediation1" }); Mockito.when(registry.get(parentCollectionPath)).thenThrow(RegistryException.class) .thenReturn(parentCollection); Mockito.when(registry.get( parentCollectionPath + RegistryConstants.PATH_SEPARATOR + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN)) .thenReturn(childCollection); Resource resource = new ResourceImpl(); resource.setUUID(SAMPLE_RESOURCE_ID); String mediationPolicyContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sequence xmlns=\"http://ws.apache.org/ns/synapse\" name=\"default-endpoint\">\n</sequence>"; resource.setContent(mediationPolicyContent); Mockito.when(registry.get("mediation1")).thenReturn(resource); AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry); try { abstractAPIManager.getAllApiSpecificMediationPolicies(identifier); Assert.fail("Registry exception not thrown for error scenario"); } catch (APIManagementException e) { Assert.assertTrue( e.getMessage().contains("Error occurred while getting Api Specific mediation policies ")); } Assert.assertEquals(abstractAPIManager.getAllApiSpecificMediationPolicies(identifier).size(), 1); PowerMockito.mockStatic(IOUtils.class); PowerMockito.mockStatic(AXIOMUtil.class); PowerMockito.when(IOUtils.toString((InputStream) Mockito.any(), Mockito.anyString())) .thenThrow(IOException.class).thenReturn(mediationPolicyContent); PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(XMLStreamException.class); abstractAPIManager.getAllApiSpecificMediationPolicies(identifier);// covers exception which is only logged abstractAPIManager.getAllApiSpecificMediationPolicies(identifier);// covers exception which is only logged }
Example 20
Source File: ApplicationImportExportManager.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Import and add subscriptions of a particular application for the available APIs * * @param appDetails details of the imported application * @param userId username of the subscriber * @param appId application Id * @return a list of APIIdentifiers of the skipped subscriptions * @throws APIManagementException if an error occurs while importing and adding subscriptions */ public List<APIIdentifier> importSubscriptions(Application appDetails, String userId, int appId, Boolean update) throws APIManagementException, UserStoreException { List<APIIdentifier> skippedAPIList = new ArrayList<>(); Set<SubscribedAPI> subscribedAPIs = appDetails.getSubscribedAPIs(); for (SubscribedAPI subscribedAPI : subscribedAPIs) { APIIdentifier apiIdentifier = subscribedAPI.getApiId(); String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack (apiIdentifier.getProviderName())); if (!StringUtils.isEmpty(tenantDomain) && APIUtil.isTenantAvailable(tenantDomain)) { String name = apiIdentifier.getApiName(); String version = apiIdentifier.getVersion(); //creating a solr compatible search query, here we will execute a search query without wildcards StringBuilder searchQuery = new StringBuilder(); String[] searchCriteria = {name, "version:" + version}; for (int i = 0; i < searchCriteria.length; i++) { if (i == 0) { searchQuery = new StringBuilder( APIUtil.getSingleSearchCriteria(searchCriteria[i]).replace("*", "")); } else { searchQuery.append(APIConstants.SEARCH_AND_TAG) .append(APIUtil.getSingleSearchCriteria(searchCriteria[i]).replace("*", "")); } } Map matchedAPIs; matchedAPIs = apiConsumer.searchPaginatedAPIs(searchQuery.toString(), tenantDomain, 0, Integer.MAX_VALUE, false); Set<API> apiSet = (Set<API>) matchedAPIs.get("apis"); if (apiSet != null && !apiSet.isEmpty()) { API api = apiSet.iterator().next(); //tier of the imported subscription Tier tier = subscribedAPI.getTier(); //checking whether the target tier is available if (isTierAvailable(tier, api) && api.getStatus() != null && APIConstants.PUBLISHED.equals(api.getStatus())) { ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api); apiTypeWrapper.setTier(tier.getName()); // add subscription if update flag is not specified // it will throw an error if subscriber already exists if (update == null || !update) { apiConsumer.addSubscription(apiTypeWrapper, userId, appId); } else if (!apiConsumer.isSubscribedToApp(subscribedAPI.getApiId(), userId, appId)) { // on update skip subscriptions that already exists apiConsumer.addSubscription(apiTypeWrapper, userId, appId); } } else { log.error("Failed to import Subscription as API " + name + "-" + version + " as one or more tiers may be unavailable or the API may not have been published "); skippedAPIList.add(subscribedAPI.getApiId()); } } else { log.error("Failed to import Subscription as API " + name + "-" + version + " is not available"); skippedAPIList.add(subscribedAPI.getApiId()); } } else { log.error("Failed to import Subscription as Tenant domain: " + tenantDomain + " is not available"); skippedAPIList.add(subscribedAPI.getApiId()); } } return skippedAPIList; }