Search in sources :

Example 96 with Environment

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());
}
Also used : Environment(org.wso2.carbon.apimgt.api.model.Environment) OMElement(org.apache.axiom.om.OMElement) Test(org.junit.Test)

Example 97 with Environment

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;
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) HashMap(java.util.HashMap) Environment(org.wso2.carbon.apimgt.api.model.Environment)

Example 98 with Environment

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();
}
Also used : Response(javax.ws.rs.core.Response) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) ArrayList(java.util.ArrayList) APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 99 with Environment

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();
}
Also used : Response(javax.ws.rs.core.Response) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) ArrayList(java.util.ArrayList) APIRevisionDeploymentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionDeploymentDTO) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 100 with Environment

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"));
}
Also used : Environment(org.wso2.carbon.apimgt.api.model.Environment) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) EnvironmentConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EnvironmentConfigContext) EnvironmentConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EnvironmentConfigContext) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) ConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.ConfigContext) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) Test(org.junit.Test)

Aggregations

Environment (org.wso2.carbon.apimgt.api.model.Environment)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 ArrayList (java.util.ArrayList)38 HashMap (java.util.HashMap)28 API (org.wso2.carbon.apimgt.api.model.API)22 IOException (java.io.IOException)20 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)19 Map (java.util.Map)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)13 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)12 JsonObject (com.google.gson.JsonObject)10 PreparedStatement (java.sql.PreparedStatement)10 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)10 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)10 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)10 Gson (com.google.gson.Gson)9 JSONObject (org.json.simple.JSONObject)9 Test (org.junit.Test)9 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)9