Search in sources :

Example 96 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.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 97 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.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 98 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.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)

Example 99 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.

the class SettingsMappingUtil method fromSettingstoDTO.

/**
 * This method feeds data into the settingsDTO.
 *
 * @param isUserAvailable check if user is logged in
 * @return SettingsDTO
 * @throws APIManagementException,IOException
 */
public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, String organization) throws APIManagementException, IOException {
    SettingsDTO settingsDTO = new SettingsDTO();
    EnvironmentListDTO environmentListDTO = new EnvironmentListDTO();
    if (isUserAvailable) {
        Map<String, Environment> environments = APIUtil.getEnvironments(organization);
        if (environments != null) {
            environmentListDTO = EnvironmentMappingUtil.fromEnvironmentCollectionToDTO(environments.values());
        }
        settingsDTO.setEnvironment(environmentListDTO.getList());
        String storeUrl = APIUtil.getStoreUrl();
        String loggedInUserTenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
        Map<String, String> domainMappings = APIUtil.getDomainMappings(loggedInUserTenantDomain, APIConstants.API_DOMAIN_MAPPINGS_STORE);
        if (domainMappings.size() != 0) {
            Iterator entries = domainMappings.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry thisEntry = (Map.Entry) entries.next();
                storeUrl = "https://" + thisEntry.getValue();
                break;
            }
        }
        settingsDTO.setDevportalUrl(storeUrl);
        settingsDTO.setMonetizationAttributes(getMonetizationAttributes());
        settingsDTO.setSecurityAuditProperties(getSecurityAuditProperties());
        settingsDTO.setExternalStoresEnabled(APIUtil.isExternalStoresEnabled(RestApiCommonUtil.getLoggedInUserTenantDomain()));
        settingsDTO.setDocVisibilityEnabled(APIUtil.isDocVisibilityLevelsEnabled());
        settingsDTO.setCrossTenantSubscriptionEnabled(APIUtil.isCrossTenantSubscriptionsEnabled());
        Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
        String authorizationHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain, APIConstants.AUTHORIZATION_HEADER);
        if (authorizationHeader == null) {
            authorizationHeader = APIConstants.AUTHORIZATION_HEADER_DEFAULT;
        }
        settingsDTO.setAuthorizationHeader(authorizationHeader);
    }
    return settingsDTO;
}
Also used : SettingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SettingsDTO) EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentListDTO) Iterator(java.util.Iterator) Environment(org.wso2.carbon.apimgt.api.model.Environment) Map(java.util.Map)

Example 100 with Environment

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.

the class RuntimeArtifactGeneratorUtil method generateMetadataArtifact.

public static RuntimeArtifactDto generateMetadataArtifact(String tenantDomain, String apiId, String gatewayLabel) throws APIManagementException {
    List<APIRuntimeArtifactDto> gatewayArtifacts = getRuntimeArtifacts(apiId, gatewayLabel, tenantDomain);
    if (gatewayArtifacts != null) {
        try {
            MetadataDescriptorDto metadataDescriptorDto = new MetadataDescriptorDto();
            Map<String, ApiMetadataProjectDto> deploymentsMap = new HashMap<>();
            // "tempDirectory" is the root artifact directory
            File tempDirectory = CommonUtil.createTempDirectory(null);
            for (APIRuntimeArtifactDto apiRuntimeArtifactDto : gatewayArtifacts) {
                if (apiRuntimeArtifactDto.isFile()) {
                    String fileName = apiRuntimeArtifactDto.getApiId().concat("-").concat(apiRuntimeArtifactDto.getRevision());
                    ApiMetadataProjectDto apiProjectDto = deploymentsMap.get(fileName);
                    if (apiProjectDto == null) {
                        apiProjectDto = new ApiMetadataProjectDto();
                        deploymentsMap.put(fileName, apiProjectDto);
                        apiProjectDto.setApiFile(fileName);
                        apiProjectDto.setEnvironments(new HashSet<>());
                        apiProjectDto.setOrganizationId(apiRuntimeArtifactDto.getOrganization());
                        apiProjectDto.setVersion(apiRuntimeArtifactDto.getVersion());
                        apiProjectDto.setApiContext(apiRuntimeArtifactDto.getContext());
                    }
                    EnvironmentDto environment = new EnvironmentDto();
                    environment.setName(apiRuntimeArtifactDto.getLabel());
                    environment.setVhost(apiRuntimeArtifactDto.getVhost());
                    apiProjectDto.getEnvironments().add(environment);
                }
            }
            metadataDescriptorDto.setMetadataDescriptor(new HashSet<>(deploymentsMap.values()));
            String descriptorFile = Paths.get(tempDirectory.getAbsolutePath(), APIConstants.GatewayArtifactConstants.DEPLOYMENT_DESCRIPTOR_FILE).toString();
            CommonUtil.writeDtoToFile(descriptorFile, ExportFormat.JSON, APIConstants.GatewayArtifactConstants.DEPLOYMENT_DESCRIPTOR_FILE_TYPE, metadataDescriptorDto);
            RuntimeArtifactDto runtimeArtifactDto = new RuntimeArtifactDto();
            runtimeArtifactDto.setArtifact(new File(descriptorFile.concat(APIConstants.JSON_FILE_EXTENSION)));
            runtimeArtifactDto.setFile(true);
            return runtimeArtifactDto;
        } catch (APIImportExportException | IOException e) {
            throw new APIManagementException("Error while Generating API artifact", e);
        }
    } else {
        throw new APIManagementException("No API Artifacts", ExceptionCodes.NO_API_ARTIFACT_FOUND);
    }
}
Also used : MetadataDescriptorDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.MetadataDescriptorDto) HashMap(java.util.HashMap) EnvironmentDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto) RuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto) APIRuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto) IOException(java.io.IOException) ApiMetadataProjectDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.ApiMetadataProjectDto) APIRuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) File(java.io.File)

Aggregations

Environment (org.wso2.carbon.apimgt.api.model.Environment)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)25 API (org.wso2.carbon.apimgt.api.model.API)22 IOException (java.io.IOException)19 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)19 Map (java.util.Map)15 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