Search in sources :

Example 1 with VHost

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);
}
Also used : VHost(org.wso2.carbon.apimgt.api.model.VHost)

Example 2 with VHost

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;
}
Also used : VHostDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.VHostDTO)

Example 3 with VHost

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) PreparedStatement(java.sql.PreparedStatement)

Example 4 with VHost

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) PreparedStatement(java.sql.PreparedStatement)

Example 5 with VHost

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;
}
Also used : SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) APIRuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet)

Aggregations

SQLException (java.sql.SQLException)14 PreparedStatement (java.sql.PreparedStatement)13 ArrayList (java.util.ArrayList)13 Connection (java.sql.Connection)12 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)11 ResultSet (java.sql.ResultSet)9 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)8 Environment (org.wso2.carbon.apimgt.api.model.Environment)8 VHost (org.wso2.carbon.apimgt.api.model.VHost)7 IOException (java.io.IOException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 APIRuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto)4 HashMap (java.util.HashMap)3 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)3 DeployedAPIRevision (org.wso2.carbon.apimgt.api.model.DeployedAPIRevision)3 JsonObject (com.google.gson.JsonObject)2 Timestamp (java.sql.Timestamp)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2