Search in sources :

Example 1 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvDtoToEnv.

/**
 * Convert EnvironmentDTO to Environment
 *
 * @param envDTO EnvironmentDTO
 * @return Environment
 */
public static Environment fromEnvDtoToEnv(EnvironmentDTO envDTO) {
    Environment env = new Environment();
    env.setUuid(envDTO.getId());
    env.setName(envDTO.getName());
    env.setDisplayName(envDTO.getDisplayName());
    env.setDescription(envDTO.getDescription());
    env.setProvider(envDTO.getProvider());
    env.setReadOnly(false);
    env.setVhosts(envDTO.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostDtoToVHost).collect(Collectors.toList()));
    env.setAdditionalProperties(fromAdditionalPropertiesDTOToAdditionalProperties(envDTO.getAdditionalProperties()));
    return env;
}
Also used : Environment(org.wso2.carbon.apimgt.api.model.Environment)

Example 2 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvToEnvDTO.

/**
 * Convert Environment to EnvironmentDTO
 *
 * @param env Environment
 * @return EnvironmentDTO containing Environment
 */
public static EnvironmentDTO fromEnvToEnvDTO(Environment env) {
    EnvironmentDTO envDTO = new EnvironmentDTO();
    envDTO.setId(env.getUuid());
    envDTO.setName(env.getName());
    envDTO.setDisplayName(env.getDisplayName());
    envDTO.setDescription(env.getDescription());
    envDTO.setProvider(env.getProvider());
    envDTO.setIsReadOnly(env.isReadOnly());
    envDTO.setVhosts(env.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostToVHostDTO).collect(Collectors.toList()));
    envDTO.setAdditionalProperties(fromAdditionalPropertiesToAdditionalPropertiesDTO(env.getAdditionalProperties()));
    return envDTO;
}
Also used : EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentDTO)

Example 3 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto in project carbon-apimgt by wso2.

the class EnvironmentsApiServiceImpl method environmentsPost.

/**
 * Create a dynamic gateway environment
 * @param body environment to be created
 * @param messageContext message context
 * @return created environment
 * @throws APIManagementException if failed to create
 */
public Response environmentsPost(EnvironmentDTO body, MessageContext messageContext) throws APIManagementException {
    try {
        APIAdmin apiAdmin = new APIAdminImpl();
        // String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        Environment env = EnvironmentMappingUtil.fromEnvDtoToEnv(body);
        EnvironmentDTO envDTO = EnvironmentMappingUtil.fromEnvToEnvDTO(apiAdmin.addEnvironment(organization, env));
        URI location = new URI(RestApiConstants.RESOURCE_PATH_ENVIRONMENT + "/" + envDTO.getId());
        return Response.created(location).entity(envDTO).build();
    } catch (URISyntaxException e) {
        String errorMessage = "Error while adding gateway environment : " + body.getName() + "-" + e.getMessage();
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentDTO) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 4 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto in project carbon-apimgt by wso2.

the class EnvironmentsApiServiceImpl method environmentsEnvironmentIdPut.

/**
 * Update gateway environment
 *
 * @param environmentId environment ID
 * @param body environment to be updated
 * @param messageContext message context
 * @return updated environment
 * @throws APIManagementException if failed to update
 */
public Response environmentsEnvironmentIdPut(String environmentId, EnvironmentDTO body, MessageContext messageContext) throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    body.setId(environmentId);
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    Environment env = EnvironmentMappingUtil.fromEnvDtoToEnv(body);
    apiAdmin.updateEnvironment(organization, env);
    URI location = null;
    try {
        location = new URI(RestApiConstants.RESOURCE_PATH_ENVIRONMENT + "/" + environmentId);
    } catch (URISyntaxException e) {
        String errorMessage = "Error while updating Environment : " + environmentId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return Response.ok(location).entity(body).build();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 5 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto in project carbon-apimgt by wso2.

the class MicroGatewayArtifactGenerator method generateGatewayArtifact.

@Override
public RuntimeArtifactDto generateGatewayArtifact(List<APIRuntimeArtifactDto> apiRuntimeArtifactDtoList) throws APIManagementException {
    try {
        DeploymentDescriptorDto descriptorDto = new DeploymentDescriptorDto();
        Map<String, ApiProjectDto> deploymentsMap = new HashMap<>();
        // "tempDirectory" is the root artifact directory
        File tempDirectory = CommonUtil.createTempDirectory(null);
        for (APIRuntimeArtifactDto apiRuntimeArtifactDto : apiRuntimeArtifactDtoList) {
            if (apiRuntimeArtifactDto.isFile()) {
                InputStream artifact = (InputStream) apiRuntimeArtifactDto.getArtifact();
                String fileName = apiRuntimeArtifactDto.getApiId().concat("-").concat(apiRuntimeArtifactDto.getRevision()).concat(APIConstants.ZIP_FILE_EXTENSION);
                Path path = Paths.get(tempDirectory.getAbsolutePath(), fileName);
                FileUtils.copyInputStreamToFile(artifact, path.toFile());
                ApiProjectDto apiProjectDto = deploymentsMap.get(fileName);
                if (apiProjectDto == null) {
                    apiProjectDto = new ApiProjectDto();
                    deploymentsMap.put(fileName, apiProjectDto);
                    apiProjectDto.setApiFile(fileName);
                    apiProjectDto.setEnvironments(new HashSet<>());
                    apiProjectDto.setOrganizationId(apiRuntimeArtifactDto.getOrganization());
                }
                // environment is unique for a revision in a deployment
                // create new environment
                EnvironmentDto environment = new EnvironmentDto();
                environment.setName(apiRuntimeArtifactDto.getLabel());
                environment.setVhost(apiRuntimeArtifactDto.getVhost());
                // ignored if the name of the environment is same
                apiProjectDto.getEnvironments().add(environment);
            }
        }
        descriptorDto.setDeployments(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, descriptorDto);
        // adding env_properties.json
        Map<String, Map<String, Environment>> environmentSpecificAPIProperties = getEnvironmentSpecificAPIProperties(apiRuntimeArtifactDtoList);
        String environmentSpecificAPIPropertyFile = Paths.get(tempDirectory.getAbsolutePath(), APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_FILE).toString();
        CommonUtil.writeDtoToFile(environmentSpecificAPIPropertyFile, ExportFormat.JSON, APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_FILE, APIConstants.GatewayArtifactConstants.ENVIRONMENT_SPECIFIC_API_PROPERTY_KEY_NAME, environmentSpecificAPIProperties);
        CommonUtil.archiveDirectory(tempDirectory.getAbsolutePath());
        FileUtils.deleteQuietly(tempDirectory);
        RuntimeArtifactDto runtimeArtifactDto = new RuntimeArtifactDto();
        runtimeArtifactDto.setArtifact(new File(tempDirectory.getAbsolutePath() + APIConstants.ZIP_FILE_EXTENSION));
        runtimeArtifactDto.setFile(true);
        return runtimeArtifactDto;
    } catch (APIImportExportException | IOException e) {
        throw new APIManagementException("Error while Generating API artifact", e);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) InputStream(java.io.InputStream) 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) ApiProjectDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.ApiProjectDto) 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) HashMap(java.util.HashMap) Map(java.util.Map) DeploymentDescriptorDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.DeploymentDescriptorDto)

Aggregations

Environment (org.wso2.carbon.apimgt.api.model.Environment)4 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)2 ExternalEnvironment (org.wso2.carbon.apimgt.impl.ExternalEnvironment)2 APIRuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto)2 RuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto)2 EnvironmentDto (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto)2 APIImportExportException (org.wso2.carbon.apimgt.impl.importexport.APIImportExportException)2 EnvironmentDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentDTO)2 EnvironmentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO)2 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1