Search in sources :

Example 31 with Broker

use of org.wso2.broker.core.Broker 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");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) Environment(org.wso2.carbon.apimgt.api.model.Environment) AdditionalSubscriptionInfoSolaceURLsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO) SolaceURLsDTO(org.wso2.carbon.apimgt.solace.dtos.SolaceURLsDTO) Map(java.util.Map) AdditionalSubscriptionInfoSolaceURLsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO)

Example 32 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method setSolaceEnvironmentDetailsForSubscription.

/**
 * Sets the solace environment details For Solace API subscription with the protocol details
 *
 * @param api          API object
 * @param tenantDomain Tenant Domain
 * @return List containing AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO
 * @throws APIManagementException if error occurred when retrieving protocols URLs
 */
private static List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> setSolaceEnvironmentDetailsForSubscription(API api, String tenantDomain) throws APIManagementException {
    APIDTO apidto = APIMappingUtil.fromAPItoDTO(api, tenantDomain);
    Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    List<APIRevisionDeployment> revisionDeployments = apiConsumer.getAPIRevisionDeploymentListOfAPI(apidto.getId());
    List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> solaceEndpointURLsList = new ArrayList<>();
    // Get revision list of APIs and check Solace deployment environment
    for (APIRevisionDeployment revisionDeployment : revisionDeployments) {
        if (revisionDeployment.isDisplayOnDevportal()) {
            if (gatewayEnvironments != null) {
                // Deployed environment
                Environment environment = gatewayEnvironments.get(revisionDeployment.getDeployment());
                if (environment != null) {
                    // Set solace environment details if deployment is in Solace broker
                    if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(environment.getProvider())) {
                        AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO solaceEnvironmentDTO = new AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO();
                        solaceEnvironmentDTO.setEnvironmentName(environment.getName());
                        solaceEnvironmentDTO.setEnvironmentDisplayName(environment.getDisplayName());
                        solaceEnvironmentDTO.setOrganizationName(environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION));
                        // Get Solace endpoint URLs for provided protocols
                        solaceEnvironmentDTO.setSolaceURLs(mapSolaceURLsToStoreDTO(environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION), environment.getName(), apidto.getAsyncTransportProtocols()));
                        solaceEndpointURLsList.add(solaceEnvironmentDTO);
                    }
                }
            }
        }
    }
    return solaceEndpointURLsList;
}
Also used : APIDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIDTO) AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO) ArrayList(java.util.ArrayList) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer)

Example 33 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class SolaceAdminApis method renameApplication.

/**
 * Rename application in Solace Broker
 *
 * @param organization name of the Organization
 * @param application  Application object to be renamed
 * @return CloseableHttpResponse of the DELETE call
 */
public CloseableHttpResponse renameApplication(String organization, Application application) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpPatch httpPatch = new HttpPatch(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + application.getUUID());
    httpPatch.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    httpPatch.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
    org.json.JSONObject requestBody = buildRequestBodyForRenamingApp(application);
    StringEntity params = null;
    try {
        params = new StringEntity(requestBody.toString());
        httpPatch.setEntity(params);
        return APIUtil.executeHTTPRequest(httpPatch, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) JSONObject(org.json.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) IOException(java.io.IOException) URL(org.apache.axis2.util.URL) HttpPatch(org.apache.http.client.methods.HttpPatch)

Example 34 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class SolaceAdminApis method deleteApiProduct.

/**
 * Delete API Product from Solace Broker
 *
 * @param organization   name of the Organization
 * @param apiProductName name of the API product
 * @return CloseableHttpResponse of the DELETE call
 */
public CloseableHttpResponse deleteApiProduct(String organization, String apiProductName) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpDelete httpDelete = new HttpDelete(baseUrl + "/" + organization + "/apiProducts/" + apiProductName);
    httpDelete.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    try {
        return APIUtil.executeHTTPRequest(httpDelete, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) IOException(java.io.IOException) URL(org.apache.axis2.util.URL)

Example 35 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class SolaceKeyGenNotifier method syncSolaceApplicationClientId.

/**
 * Syncing consumer key of the dev portal applications with applications on the Solace broker
 *
 * @param event ApplicationEvent to sync Solace applications with dev portal applications
 * @throws NotifierException if error occurs when patching applications on the Solace broker
 */
private void syncSolaceApplicationClientId(ApplicationRegistrationEvent event) throws NotifierException {
    // get list of subscribed APIs in the application
    try {
        Application application = apiMgtDAO.getApplicationByUUID(event.getApplicationUUID());
        Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
        Set<SubscribedAPI> subscriptions = apiMgtDAO.getSubscribedAPIs(application.getSubscriber(), application.getName(), application.getGroupId());
        boolean isContainsSolaceApis = false;
        String organizationNameOfSolaceDeployment = null;
        labelOne: // Check whether the application needs to be updated has a Solace API subscription
        for (SubscribedAPI api : subscriptions) {
            List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentByApiUUID(api.getIdentifier().getUUID());
            for (APIRevisionDeployment deployment : deployments) {
                if (gatewayEnvironments.containsKey(deployment.getDeployment())) {
                    if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(gatewayEnvironments.get(deployment.getDeployment()).getProvider())) {
                        isContainsSolaceApis = true;
                        organizationNameOfSolaceDeployment = gatewayEnvironments.get(deployment.getDeployment()).getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION);
                        break labelOne;
                    }
                }
            }
        }
        // Patching consumerKey to Solace application using Admin Apis
        if (isContainsSolaceApis) {
            if (application.getKeys() != null) {
                String consumerSecret = null;
                APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(CarbonContext.getThreadLocalCarbonContext().getUsername());
                Set<APIKey> consumerKeys = apiConsumer.getApplicationKeysOfApplication(application.getId());
                for (APIKey key : consumerKeys) {
                    if (key.getConsumerKey().equals(event.getConsumerKey())) {
                        consumerSecret = key.getConsumerSecret();
                    }
                }
                SolaceNotifierUtils.patchSolaceApplicationClientId(organizationNameOfSolaceDeployment, application, event.getConsumerKey(), consumerSecret);
            } else {
                throw new NotifierException("Application keys are not found in the application : " + application.getName());
            }
        }
    } catch (APIManagementException e) {
        throw new NotifierException(e.getMessage());
    }
}
Also used : APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException) APIKey(org.wso2.carbon.apimgt.api.model.APIKey) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Environment(org.wso2.carbon.apimgt.api.model.Environment) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) List(java.util.List) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) Application(org.wso2.carbon.apimgt.api.model.Application)

Aggregations

Test (org.testng.annotations.Test)19 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)19 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)16 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 Environment (org.wso2.carbon.apimgt.api.model.Environment)15 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)13 ArrayList (java.util.ArrayList)11 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)9 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 DeployerException (org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException)7 NotifierException (org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)7 IOException (java.io.IOException)6 Broker (org.wso2.carbon.apimgt.core.api.Broker)6 Test (org.junit.Test)5 API (org.wso2.carbon.apimgt.core.models.API)5 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4 ExternalGatewayDeployer (org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer)4 JsonParser (com.google.gson.JsonParser)3