use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class VHostUtils method getVhostFromEnvironment.
/**
* Get VHost object of given environment and given host name
*
* @param environment Gateway environment name
* @param host Host name of the VHost
* @return VHost object of the given host
*/
public static VHost getVhostFromEnvironment(Environment environment, String host) {
// If there are any inconstancy (if VHost not found) use default VHost
VHost defaultVhost = new VHost();
defaultVhost.setHost(host);
defaultVhost.setHttpContext("");
defaultVhost.setHttpsPort(APIConstants.HTTPS_PROTOCOL_PORT);
defaultVhost.setHttpPort(APIConstants.HTTP_PROTOCOL_PORT);
defaultVhost.setWsPort(APIConstants.WS_PROTOCOL_PORT);
defaultVhost.setWssPort(APIConstants.WSS_PROTOCOL_PORT);
if (host == null && environment.getVhosts().size() > 0) {
// VHost is NULL set first Vhost (set in deployment toml)
return environment.getVhosts().get(0);
}
return environment.getVhosts().stream().filter(v -> StringUtils.equals(v.getHost(), host)).findAny().orElse(defaultVhost);
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class EnvironmentMappingUtil method fromVHostToVHostDTO.
/**
* Convert VHost to VHostDTO
*
* @param vHost VHost
* @return VHostDTO
*/
public static VHostDTO fromVHostToVHostDTO(VHost vHost) {
VHostDTO vHostDTO = new VHostDTO();
vHostDTO.setHost(vHost.getHost());
vHostDTO.setHttpContext(vHost.getHttpContext());
vHostDTO.setHttpPort(vHost.getHttpPort());
vHostDTO.setHttpsPort(vHost.getHttpsPort());
vHostDTO.setWsPort(vHost.getWsPort());
vHostDTO.setWssPort(vHost.getWssPort());
return vHostDTO;
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAPIRevisionDeploymentByRevisionUUID.
/**
* Get APIRevisionDeployment details by providing revision uuid
*
* @return List<APIRevisionDeployment> object
* @throws APIManagementException if an error occurs while retrieving revision deployment mapping details
*/
public List<APIRevisionDeployment> getAPIRevisionDeploymentByRevisionUUID(String revisionUUID) throws APIManagementException {
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.GET_API_REVISION_DEPLOYMENT_MAPPING_BY_REVISION_UUID)) {
statement.setString(1, revisionUUID);
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
String environmentName = rs.getString("NAME");
String vhost = rs.getString("VHOST");
apiRevisionDeployment.setDeployment(environmentName);
apiRevisionDeployment.setVhost(VHostUtils.resolveIfNullToDefaultVhost(environmentName, vhost));
apiRevisionDeployment.setRevisionUUID(rs.getString("REVISION_UUID"));
apiRevisionDeployment.setDisplayOnDevportal(rs.getBoolean("DISPLAY_ON_DEVPORTAL"));
apiRevisionDeployment.setDeployedTime(rs.getString("DEPLOYED_TIME"));
apiRevisionDeploymentList.add(apiRevisionDeployment);
}
}
} catch (SQLException e) {
handleException("Failed to get API Revision deployment mapping details for revision uuid: " + revisionUUID, e);
}
return apiRevisionDeploymentList;
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAPIRevisionDeploymentsByApiUUID.
/**
* Get APIRevisionDeployment details by providing ApiUUID
*
* @return List<APIRevisionDeployment> object
* @throws APIManagementException if an error occurs while retrieving revision deployment mapping details
*/
public List<APIRevisionDeployment> getAPIRevisionDeploymentsByApiUUID(String apiUUID) throws APIManagementException {
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.GET_API_REVISION_DEPLOYMENT_MAPPING_BY_API_UUID)) {
statement.setString(1, apiUUID);
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
String environmentName = rs.getString("NAME");
String vhost = rs.getString("VHOST");
apiRevisionDeployment.setDeployment(environmentName);
apiRevisionDeployment.setVhost(VHostUtils.resolveIfNullToDefaultVhost(environmentName, vhost));
apiRevisionDeployment.setRevisionUUID(rs.getString("REVISION_UUID"));
apiRevisionDeployment.setDisplayOnDevportal(rs.getBoolean("DISPLAY_ON_DEVPORTAL"));
apiRevisionDeployment.setDeployedTime(rs.getString("DEPLOYED_TIME"));
apiRevisionDeploymentList.add(apiRevisionDeployment);
}
}
} catch (SQLException e) {
handleException("Failed to get API Revision deployment mapping details for api uuid: " + apiUUID, e);
}
return apiRevisionDeploymentList;
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class GatewayArtifactsMgtDAO method retrieveGatewayArtifacts.
public List<APIRuntimeArtifactDto> retrieveGatewayArtifacts(String tenantDomain) throws APIManagementException {
String query = SQLConstants.RETRIEVE_ARTIFACTS;
List<APIRuntimeArtifactDto> apiRuntimeArtifactDtoList = new ArrayList<>();
try (Connection connection = GatewayArtifactsMgtDBUtil.getArtifactSynchronizerConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, tenantDomain);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String apiId = resultSet.getString("API_ID");
String label = resultSet.getString("LABEL");
try {
APIRuntimeArtifactDto apiRuntimeArtifactDto = new APIRuntimeArtifactDto();
apiRuntimeArtifactDto.setTenantDomain(resultSet.getString("TENANT_DOMAIN"));
apiRuntimeArtifactDto.setApiId(apiId);
String resolvedVhost = VHostUtils.resolveIfNullToDefaultVhost(label, resultSet.getString("VHOST"));
apiRuntimeArtifactDto.setLabel(label);
apiRuntimeArtifactDto.setVhost(resolvedVhost);
apiRuntimeArtifactDto.setName(resultSet.getString("API_NAME"));
apiRuntimeArtifactDto.setVersion(resultSet.getString("API_VERSION"));
apiRuntimeArtifactDto.setProvider(resultSet.getString("API_PROVIDER"));
apiRuntimeArtifactDto.setRevision(resultSet.getString("REVISION_ID"));
apiRuntimeArtifactDto.setType(resultSet.getString("API_TYPE"));
apiRuntimeArtifactDto.setContext(resultSet.getString("CONTEXT"));
InputStream artifact = resultSet.getBinaryStream("ARTIFACT");
if (artifact != null) {
byte[] artifactByte = APIMgtDBUtil.getBytesFromInputStream(artifact);
try (InputStream newArtifact = new ByteArrayInputStream(artifactByte)) {
apiRuntimeArtifactDto.setArtifact(newArtifact);
}
}
apiRuntimeArtifactDto.setFile(true);
apiRuntimeArtifactDtoList.add(apiRuntimeArtifactDto);
} catch (APIManagementException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Error resolving vhost while retrieving runtime artifact for API %s, " + "gateway environment \"%s\", tenant: \"%s\"." + "Skipping runtime artifact for the API.", apiId, label, tenantDomain), e);
} catch (IOException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Error occurred retrieving input stream from byte array of " + "API: %s, gateway environment \"%s\", tenant: \"%s\".", apiId, label, tenantDomain), e);
} catch (SQLException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Failed to retrieve Gateway Artifact of API: %s, " + "gateway environment \"%s\", tenant: \"%s\".", apiId, label, tenantDomain), e);
}
}
}
} catch (SQLException e) {
handleException("Failed to retrieve Gateway Artifacts.", e);
}
return apiRuntimeArtifactDtoList;
}
Aggregations