use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class APIManagerConfigurationTest method testEnvironmentsConfigProvided.
@Test
public void testEnvironmentsConfigProvided() throws XMLStreamException, APIManagementException {
String envConfig = "<Environment type=\"hybrid\" api-console=\"true\" isDefault=\"true\">\n" + " <Name>Default</Name>\n" + " <DisplayName></DisplayName>\n" + " <Description>This is a hybrid gateway that handles both production and sandbox token traffic.</Description>\n" + " <!-- Server URL of the API gateway -->\n" + " <ServerURL>https://localhost:9440/services/</ServerURL>\n" + " <!-- Admin username for the API gateway. -->\n" + " <Username>${admin.username}</Username>\n" + " <!-- Admin password for the API gateway.-->\n" + " <Password>${admin.password}</Password>\n" + " <!-- Provider Vendor of the API gateway.-->\n" + " <Provider>wso2</Provider>\n" + " <!-- Endpoint URLs for the APIs hosted in this API gateway.-->\n" + " <GatewayEndpoint>https://localhost:9440,http://localhost:9440</GatewayEndpoint>\n" + " <!-- Additional properties for External Gateways -->\n" + " <!-- Endpoint URLs of the WebSocket APIs hosted in this API Gateway -->\n" + " <GatewayWSEndpoint>ws://localhost:9099,wss://localhost:8099</GatewayWSEndpoint>\n" + " <!-- Endpoint URLs of the WebSub APIs hosted in this API Gateway -->\n" + " <GatewayWebSubEndpoint>http://localhost:9021,https://localhost:8021</GatewayWebSubEndpoint>\n" + " <VirtualHosts>\n" + " </VirtualHosts>\n" + " </Environment>";
OMElement element = AXIOMUtil.stringToOM(envConfig);
APIManagerConfiguration config = new APIManagerConfiguration();
config.setEnvironmentConfig(element);
Map<String, Environment> environmentsList = config.getGatewayEnvironments();
Assert.assertFalse(environmentsList.isEmpty());
Environment defaultEnv = environmentsList.get("Default");
Assert.assertEquals(defaultEnv.getProvider(), "wso2");
Assert.assertTrue(defaultEnv.getAdditionalProperties().isEmpty());
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class TestUtils method mockAPIMConfiguration.
public static ServiceReferenceHolder mockAPIMConfiguration(String propertyName, String value, int tenantId) throws RegistryException, UserStoreException, XMLStreamException {
ServiceReferenceHolder sh = mockRegistryAndUserRealm(tenantId);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
PowerMockito.when(amConfig.getFirstProperty(propertyName)).thenReturn(value);
Map<String, Environment> apiGatewayEnvironments = new HashMap<String, Environment>();
Environment env1 = new Environment();
apiGatewayEnvironments.put("PROD", env1);
// Mocking some commonly used configs
PowerMockito.when(amConfig.getApiGatewayEnvironments()).thenReturn(apiGatewayEnvironments);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_GATEWAY_TYPE)).thenReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_API_DOC_VISIBILITY_LEVELS)).thenReturn("true", "false");
return sh;
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method deployAPIProductRevision.
@Override
public Response deployAPIProductRevision(String apiProductId, String revisionId, List<APIRevisionDeploymentDTO> apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
List<APIRevisionDeployment> apiRevisionDeployments = new ArrayList<>();
for (APIRevisionDeploymentDTO apiRevisionDeploymentDTO : apIRevisionDeploymentDTO) {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setRevisionUUID(revisionId);
String environment = apiRevisionDeploymentDTO.getName();
if (environments.get(environment) == null) {
RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
}
apiRevisionDeployment.setDeployment(environment);
apiRevisionDeployment.setVhost(apiRevisionDeploymentDTO.getVhost());
if (StringUtils.isEmpty(apiRevisionDeploymentDTO.getVhost())) {
// vhost is only required when deploying an revision, not required when un-deploying a revision
// since the same scheme 'APIRevisionDeployment' is used for deploy and undeploy, handle it here.
RestApiUtil.handleBadRequest("Required field 'vhost' not found in deployment", log);
}
apiRevisionDeployment.setDisplayOnDevportal(apiRevisionDeploymentDTO.isDisplayOnDevportal());
apiRevisionDeployments.add(apiRevisionDeployment);
}
apiProvider.deployAPIProductRevision(apiProductId, revisionId, apiRevisionDeployments);
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeploymentList(revisionId);
List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsResponse) {
apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
}
Response.Status status = Response.Status.CREATED;
return Response.status(status).entity(apiRevisionDeploymentDTOS).build();
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method undeployAPIProductRevision.
@Override
public Response undeployAPIProductRevision(String apiProductId, String revisionId, String revisionNumber, Boolean allEnvironments, List<APIRevisionDeploymentDTO> apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
if (revisionId == null && revisionNumber != null) {
revisionId = apiProvider.getAPIRevisionUUID(revisionNumber, apiProductId);
if (revisionId == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(null).build();
}
}
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
List<APIRevisionDeployment> apiRevisionDeployments = new ArrayList<>();
if (allEnvironments) {
apiRevisionDeployments = apiProvider.getAPIRevisionDeploymentList(revisionId);
} else {
for (APIRevisionDeploymentDTO apiRevisionDeploymentDTO : apIRevisionDeploymentDTO) {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setRevisionUUID(revisionId);
String environment = apiRevisionDeploymentDTO.getName();
if (environments.get(environment) == null) {
RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
}
apiRevisionDeployment.setDeployment(environment);
apiRevisionDeployment.setVhost(apiRevisionDeploymentDTO.getVhost());
apiRevisionDeployment.setDisplayOnDevportal(apiRevisionDeploymentDTO.isDisplayOnDevportal());
apiRevisionDeployments.add(apiRevisionDeployment);
}
}
apiProvider.undeployAPIProductRevisionDeployment(apiProductId, revisionId, apiRevisionDeployments);
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = apiProvider.getAPIRevisionDeploymentList(revisionId);
List<APIRevisionDeploymentDTO> apiRevisionDeploymentDTOS = new ArrayList<>();
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeploymentsResponse) {
apiRevisionDeploymentDTOS.add(APIMappingUtil.fromAPIRevisionDeploymenttoDTO(apiRevisionDeployment));
}
Response.Status status = Response.Status.CREATED;
return Response.status(status).entity(apiRevisionDeploymentDTOS).build();
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class EnvironmentConfigContextTest method testEnvironmentConfigContext.
@Test
public void testEnvironmentConfigContext() throws Exception {
API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0"));
api.setStatus(APIConstants.CREATED);
api.setContextTemplate("/");
String url = "http://maps.googleapis.com/maps/api/geocode/json?address=Colombo";
String endpointConfig = "{\"production_endpoints\":{\"url\":\"" + url + "\", \"config\":null}," + "\"sandbox_endpoint\":{\"url\":\"" + url + "\",\"config\":null},\"endpoint_type\":\"http\"}";
api.setEndpointConfig(endpointConfig);
api.setUrl(url);
api.setSandboxUrl(url);
ConfigContext configcontext = new APIConfigContext(api);
Environment environment = new Environment();
environment.setType("production");
EnvironmentConfigContext environmentConfigContext = new EnvironmentConfigContext(configcontext, environment);
Assert.assertNotNull(environmentConfigContext.getContext().get("environment"));
Assert.assertNotNull(environmentConfigContext.getContext().get("environmentType"));
}
Aggregations