use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ApiMgtDAO method addAPIRevisionDeployment.
/**
* Adds an API revision Deployment mapping record to the database
*
* @param apiRevisionId uuid of the revision
* @param apiRevisionDeployments content of the revision deployment mapping objects
* @throws APIManagementException if an error occurs when adding a new API revision
*/
public void addAPIRevisionDeployment(String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeployments) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection()) {
try {
connection.setAutoCommit(false);
// Adding to AM_DEPLOYMENT_REVISION_MAPPING table
PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.ADD_API_REVISION_DEPLOYMENT_MAPPING);
for (APIRevisionDeployment apiRevisionDeployment : apiRevisionDeployments) {
String envName = apiRevisionDeployment.getDeployment();
String vhost = apiRevisionDeployment.getVhost();
// set VHost as null, if it is the default vhost of the read only environment
statement.setString(1, apiRevisionDeployment.getDeployment());
statement.setString(2, VHostUtils.resolveIfDefaultVhostToNull(envName, vhost));
statement.setString(3, apiRevisionId);
statement.setBoolean(4, apiRevisionDeployment.isDisplayOnDevportal());
statement.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
statement.addBatch();
}
statement.executeBatch();
connection.commit();
} catch (SQLException e) {
connection.rollback();
handleException("Failed to add API Revision Deployment Mapping entry for Revision UUID " + apiRevisionId, e);
}
} catch (SQLException e) {
handleException("Failed to add API Revision Deployment Mapping entry for Revision UUID " + apiRevisionId, e);
}
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ExternalGatewayNotifier method deployApi.
/**
* Deploy APIs to external gateway
*
* @param deployAPIInGatewayEvent DeployAPIInGatewayEvent to deploy APIs to external gateway
* @throws NotifierException if error occurs when deploying APIs to external gateway
*/
private void deployApi(DeployAPIInGatewayEvent deployAPIInGatewayEvent) throws NotifierException {
boolean deployed;
Set<String> gateways = deployAPIInGatewayEvent.getGatewayLabels();
String apiId = deployAPIInGatewayEvent.getUuid();
try {
Map<String, Environment> environments = APIUtil.getEnvironments(deployAPIInGatewayEvent.getTenantDomain());
APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
for (String deploymentEnv : gateways) {
if (environments.containsKey(deploymentEnv)) {
ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(environments.get(deploymentEnv).getProvider());
if (deployer != null) {
try {
deployed = deployer.deploy(api, environments.get(deploymentEnv));
if (!deployed) {
throw new APIManagementException("Error while deploying API product to Solace broker");
}
} catch (DeployerException e) {
throw new APIManagementException(e.getMessage());
}
}
}
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ExternallyDeployedApiNotifier method undeployWhenDeleting.
/**
* Undeploy APIs from external gateway when API is deleted
*
* @param apiEvent APIEvent to undeploy APIs from external gateway
* @throws NotifierException if error occurs when undeploying APIs from external gateway
*/
private void undeployWhenDeleting(APIEvent apiEvent) throws NotifierException {
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
boolean deleted;
String apiId = apiEvent.getUuid();
try {
List<APIRevisionDeployment> test = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiId);
for (APIRevisionDeployment deployment : test) {
String deploymentEnv = deployment.getDeployment();
if (gatewayEnvironments.containsKey(deploymentEnv)) {
ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(gatewayEnvironments.get(deploymentEnv).getProvider());
if (deployer != null) {
try {
deleted = deployer.undeploy(apiEvent.getApiName(), apiEvent.getApiVersion(), apiEvent.getApiContext(), gatewayEnvironments.get(deploymentEnv));
if (!deleted) {
throw new NotifierException("Error while deleting API product from Solace broker");
}
} catch (DeployerException e) {
throw new NotifierException(e.getMessage());
}
}
}
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class APIManagerConfigurationTest method testEnvironmentsConfigProvided.
@Test
public void testEnvironmentsConfigProvided() throws XMLStreamException, APIManagementException {
String envConfig = "<Environment type=\"hybrid\" api-console=\"true\" isDefault=\"true\">\n" + " <Name>Default</Name>\n" + " <DisplayName></DisplayName>\n" + " <Description>This is a hybrid gateway that handles both production and sandbox token traffic.</Description>\n" + " <!-- Server URL of the API gateway -->\n" + " <ServerURL>https://localhost:9440/services/</ServerURL>\n" + " <!-- Admin username for the API gateway. -->\n" + " <Username>${admin.username}</Username>\n" + " <!-- Admin password for the API gateway.-->\n" + " <Password>${admin.password}</Password>\n" + " <!-- Provider Vendor of the API gateway.-->\n" + " <Provider>wso2</Provider>\n" + " <!-- Endpoint URLs for the APIs hosted in this API gateway.-->\n" + " <GatewayEndpoint>https://localhost:9440,http://localhost:9440</GatewayEndpoint>\n" + " <!-- Additional properties for External Gateways -->\n" + " <!-- Endpoint URLs of the WebSocket APIs hosted in this API Gateway -->\n" + " <GatewayWSEndpoint>ws://localhost:9099,wss://localhost:8099</GatewayWSEndpoint>\n" + " <!-- Endpoint URLs of the WebSub APIs hosted in this API Gateway -->\n" + " <GatewayWebSubEndpoint>http://localhost:9021,https://localhost:8021</GatewayWebSubEndpoint>\n" + " <VirtualHosts>\n" + " </VirtualHosts>\n" + " </Environment>";
OMElement element = AXIOMUtil.stringToOM(envConfig);
APIManagerConfiguration config = new APIManagerConfiguration();
config.setEnvironmentConfig(element);
Map<String, Environment> environmentsList = config.getGatewayEnvironments();
Assert.assertFalse(environmentsList.isEmpty());
Environment defaultEnv = environmentsList.get("Default");
Assert.assertEquals(defaultEnv.getProvider(), "wso2");
Assert.assertTrue(defaultEnv.getAdditionalProperties().isEmpty());
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class TestUtils method mockAPIMConfiguration.
public static ServiceReferenceHolder mockAPIMConfiguration(String propertyName, String value, int tenantId) throws RegistryException, UserStoreException, XMLStreamException {
ServiceReferenceHolder sh = mockRegistryAndUserRealm(tenantId);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
PowerMockito.when(amConfig.getFirstProperty(propertyName)).thenReturn(value);
Map<String, Environment> apiGatewayEnvironments = new HashMap<String, Environment>();
Environment env1 = new Environment();
apiGatewayEnvironments.put("PROD", env1);
// Mocking some commonly used configs
PowerMockito.when(amConfig.getApiGatewayEnvironments()).thenReturn(apiGatewayEnvironments);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_GATEWAY_TYPE)).thenReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_API_DOC_VISIBILITY_LEVELS)).thenReturn("true", "false");
return sh;
}
Aggregations