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();
}
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();
}
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"));
}
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;
}
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);
}
}
Aggregations