use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method getThirdPartySolaceBrokerOrganizationNameOfAPIDeployment.
/**
* Get third party Solace broker organization Name for API deployment
*
* @param api Name of the API
* @return String of the name of organization in Solace broker
* @throws APIManagementException is error occurs when getting the name of the organization name
*/
public static String getThirdPartySolaceBrokerOrganizationNameOfAPIDeployment(API api) throws APIManagementException {
apiMgtDAO = ApiMgtDAO.getInstance();
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentByApiUUID(api.getUuid());
for (APIRevisionDeployment deployment : deployments) {
if (deployment.isDisplayOnDevportal()) {
String environmentName = deployment.getDeployment();
if (gatewayEnvironments.containsKey(environmentName)) {
Environment deployedEnvironment = gatewayEnvironments.get(environmentName);
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(deployedEnvironment.getProvider())) {
return deployedEnvironment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION);
}
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method isSolaceEnvironmentAdded.
/**
* Check whether the Solace is Added as a third party environment
*
* @return true if Solace is Added as a third party environment
*/
private boolean isSolaceEnvironmentAdded() {
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
if (gatewayEnvironments.isEmpty()) {
return false;
}
Environment solaceEnvironment = null;
for (Map.Entry<String, Environment> entry : gatewayEnvironments.entrySet()) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
solaceEnvironment = entry.getValue();
}
}
return solaceEnvironment != null;
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method unsubscribeAPIProductFromSolaceApplication.
/**
* Unsubscribe the given API product from the Solace application
*
* @param api API object to be unsubscribed
* @param application Solace application
* @throws APIManagementException is error occurs when unsubscribing the API from application
*/
public static void unsubscribeAPIProductFromSolaceApplication(API api, Application application) throws APIManagementException {
List<Environment> deployedSolaceEnvironments = getDeployedSolaceEnvironmentsFromRevisionDeployments(api);
String applicationOrganizationName = getSolaceOrganizationName(deployedSolaceEnvironments);
ArrayList<String> solaceApiProducts = new ArrayList<>();
if (applicationOrganizationName != null) {
for (Environment environment : deployedSolaceEnvironments) {
solaceApiProducts.add(generateApiProductNameForSolaceBroker(api, environment.getName()));
}
SolaceAdminApis solaceAdminApis = SolaceNotifierUtils.getSolaceAdminApis();
CloseableHttpResponse response = solaceAdminApis.applicationPatchRemoveSubscription(applicationOrganizationName, application, solaceApiProducts);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
try {
String responseString = EntityUtils.toString(response.getEntity());
org.json.JSONObject jsonObject = new org.json.JSONObject(responseString);
String applicationName = String.valueOf(jsonObject.get("displayName"));
log.info("API product unsubscribed from Solace application '" + applicationName + "'");
if (jsonObject.getJSONArray("apiProducts") != null) {
if (jsonObject.getJSONArray("apiProducts").length() == 0) {
// delete application in Solace because of 0 number of api products
CloseableHttpResponse response2 = solaceAdminApis.deleteApplication(applicationOrganizationName, application.getUUID());
if (response2.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) {
log.info("Successfully deleted application '" + applicationName + "' in " + "Solace Broker");
} else {
if (log.isDebugEnabled()) {
log.error("Error while deleting application '" + applicationName + "' " + "in Solace. : " + response2.getStatusLine().toString());
}
throw new APIManagementException("Error while deleting application '" + applicationName + "' in Solace");
}
}
}
} catch (IOException e) {
log.error(e.getMessage());
throw new APIManagementException("Error while deleting application in Solace");
}
} else {
if (log.isDebugEnabled()) {
log.error("Error while unsubscribing API product from Solace Application '" + application.getName() + " : " + response.getStatusLine().toString());
}
throw new APIManagementException(response.getStatusLine().getStatusCode() + "-" + response.getStatusLine().getReasonPhrase());
}
} else {
throw new APIManagementException("Multiple Solace organizations found");
}
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method mapSolaceURLsToStoreDTO.
/**
* Sets the Endpoint URLs For Solace API according to the protocols
*
* @param organizationName Solace broker organization name
* @param environmentName Name of the Solace environment
* @param availableProtocols List of available protocols
* @return List containing AdditionalSubscriptionInfoSolaceURLsDTO
* @throws APIManagementException if error occurred when retrieving protocols URLs from Solace broker
*/
private static List<AdditionalSubscriptionInfoSolaceURLsDTO> mapSolaceURLsToStoreDTO(String organizationName, String environmentName, List<String> availableProtocols) throws APIManagementException {
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
Environment solaceEnvironment = null;
// Get Solace broker environment details
for (Map.Entry<String, Environment> entry : gatewayEnvironments.entrySet()) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
solaceEnvironment = entry.getValue();
}
}
if (solaceEnvironment != null) {
List<SolaceURLsDTO> solaceURLsDTOEntries = SolaceStoreUtils.getSolaceURLsInfo(solaceEnvironment, organizationName, environmentName, availableProtocols);
List<AdditionalSubscriptionInfoSolaceURLsDTO> solaceURLsDTOs = new ArrayList<>();
for (SolaceURLsDTO entry : solaceURLsDTOEntries) {
AdditionalSubscriptionInfoSolaceURLsDTO subscriptionInfoSolaceProtocolURLsDTO = new AdditionalSubscriptionInfoSolaceURLsDTO();
subscriptionInfoSolaceProtocolURLsDTO.setProtocol(entry.getProtocol());
subscriptionInfoSolaceProtocolURLsDTO.setEndpointURL(entry.getEndpointURL());
solaceURLsDTOs.add(subscriptionInfoSolaceProtocolURLsDTO);
}
return solaceURLsDTOs;
} else {
throw new APIManagementException("Solace Environment configurations are not provided properly");
}
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoToDTO.
/**
* Converts a AdditionalSubscriptionInfo object into AdditionalSubscriptionInfoDTO
*
* @param subscription SubscribedAPI object
* @param organization Identifier of the organization
* @return SubscriptionDTO corresponds to SubscribedAPI object
*/
public static AdditionalSubscriptionInfoDTO fromAdditionalSubscriptionInfoToDTO(SubscribedAPI subscription, String organization) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
AdditionalSubscriptionInfoDTO additionalSubscriptionInfoDTO = new AdditionalSubscriptionInfoDTO();
additionalSubscriptionInfoDTO.setSubscriptionId(subscription.getUUID());
APIIdentifier apiId = subscription.getApiId();
API api = null;
if (apiId != null) {
try {
api = apiConsumer.getLightweightAPIByUUID(apiId.getUUID(), organization);
} catch (APIManagementException e) {
String msg = "User :" + username + " does not have access to the API " + apiId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
}
additionalSubscriptionInfoDTO.setApiId(api.getUuid());
// Set Application information
Application application = subscription.getApplication();
application = apiConsumer.getApplicationByUUID(application.getUUID());
additionalSubscriptionInfoDTO.setApplicationId(subscription.getApplication().getUUID());
additionalSubscriptionInfoDTO.setApplicationName(application.getName());
additionalSubscriptionInfoDTO.setIsSolaceAPI(SolaceNotifierUtils.checkWhetherAPIDeployedToSolaceUsingRevision(api));
if (additionalSubscriptionInfoDTO.isIsSolaceAPI()) {
// Set Solace organization details if API is a Solace API
additionalSubscriptionInfoDTO.setSolaceOrganization(SolaceNotifierUtils.getThirdPartySolaceBrokerOrganizationNameOfAPIDeployment(api));
Map<String, Environment> gatewayEnvironmentMap = APIUtil.getReadOnlyGatewayEnvironments();
Environment solaceEnvironment = null;
for (Map.Entry<String, Environment> entry : gatewayEnvironmentMap.entrySet()) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
solaceEnvironment = entry.getValue();
}
}
if (solaceEnvironment != null) {
List<SolaceDeployedEnvironmentDTO> solaceDeployedEnvironmentsDTOS = SolaceStoreUtils.getSolaceDeployedEnvsInfo(solaceEnvironment, additionalSubscriptionInfoDTO.getSolaceOrganization(), application.getUUID());
List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> solaceEnvironments = new ArrayList<>();
for (SolaceDeployedEnvironmentDTO solaceDeployedEnvironmentEntry : solaceDeployedEnvironmentsDTOS) {
// Set Solace environment details
AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO solaceDeployedEnvironmentsDTO = new AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO();
solaceDeployedEnvironmentsDTO.setEnvironmentName(solaceDeployedEnvironmentEntry.getEnvironmentName());
solaceDeployedEnvironmentsDTO.setEnvironmentDisplayName(solaceDeployedEnvironmentEntry.getEnvironmentDisplayName());
solaceDeployedEnvironmentsDTO.setOrganizationName(solaceDeployedEnvironmentEntry.getOrganizationName());
// Set Solace URLs
List<AdditionalSubscriptionInfoSolaceURLsDTO> endpointUrls = new ArrayList<>();
List<SolaceURLsDTO> solaceURLsDTOS = solaceDeployedEnvironmentEntry.getSolaceURLs();
for (SolaceURLsDTO entry : solaceURLsDTOS) {
AdditionalSubscriptionInfoSolaceURLsDTO solaceURLsDTO = new AdditionalSubscriptionInfoSolaceURLsDTO();
solaceURLsDTO.setProtocol(entry.getProtocol());
solaceURLsDTO.setEndpointURL(entry.getEndpointURL());
endpointUrls.add(solaceURLsDTO);
}
solaceDeployedEnvironmentsDTO.setSolaceURLs(endpointUrls);
// Set Solace Topic Objects
solaceDeployedEnvironmentsDTO.setSolaceTopicsObject(mapSolaceTopicObjects(solaceDeployedEnvironmentEntry.getSolaceTopicsObject()));
solaceEnvironments.add(solaceDeployedEnvironmentsDTO);
}
additionalSubscriptionInfoDTO.setSolaceDeployedEnvironments(solaceEnvironments);
}
}
return additionalSubscriptionInfoDTO;
}
Aggregations