use of org.wso2.carbon.apimgt.api.model.subscription.API in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method addApiPolicy.
@Override
public String addApiPolicy(APIPolicy policy) throws APIManagementException {
try {
String policyUuid = policy.getUuid();
if (policyUuid == null) {
if (log.isDebugEnabled()) {
log.debug("Policy id is null, hence generating a new UUID for the policy with name: " + policy.getPolicyName());
}
policyUuid = UUID.randomUUID().toString();
policy.setUuid(policyUuid);
}
policyDAO.addApiPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
apiGateway.addPolicy(policyValidationData);
return policyUuid;
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't add API policy for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.api.model.subscription.API in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method getAPIsByStatus.
@Override
public List<API> getAPIsByStatus(List<String> gatewayLabels, String status) throws APIManagementException {
List<API> apiList;
try {
if (gatewayLabels != null && status != null) {
apiList = apiDAO.getAPIsByStatus(gatewayLabels, status);
} else {
if (gatewayLabels == null) {
String msg = "Gateway labels cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
} else {
String msg = "Status cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.STATUS_CANNOT_BE_NULL);
}
}
} catch (APIMgtDAOException e) {
String msg = "Error occurred while getting the API list in given states";
log.error(msg, e);
throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
return apiList;
}
use of org.wso2.carbon.apimgt.api.model.subscription.API in project carbon-apimgt by wso2.
the class KubernetesGatewayImpl method createContainerGateway.
/**
* @see ContainerBasedGatewayGenerator#createContainerGateway(String, API)
*/
@Override
public void createContainerGateway(String label, API api) throws ContainerBasedGatewayException {
Map<String, String> templateValues = new HashMap<>();
String serviceName = label + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
String deploymentName = label + ContainerBasedGatewayConstants.CMS_DEPLOYMENT_SUFFIX;
String ingressName = label + ContainerBasedGatewayConstants.CMS_INGRESS_SUFFIX;
templateValues.put(ContainerBasedGatewayConstants.NAMESPACE, namespace);
templateValues.put(ContainerBasedGatewayConstants.GATEWAY_LABEL, label);
templateValues.put(ContainerBasedGatewayConstants.SERVICE_NAME, serviceName);
templateValues.put(ContainerBasedGatewayConstants.DEPLOYMENT_NAME, deploymentName);
templateValues.put(ContainerBasedGatewayConstants.INGRESS_NAME, ingressName);
templateValues.put(ContainerBasedGatewayConstants.CONTAINER_NAME, label + ContainerBasedGatewayConstants.CMS_CONTAINER_SUFFIX);
templateValues.put(ContainerBasedGatewayConstants.API_CORE_URL, apiCoreUrl);
templateValues.put(ContainerBasedGatewayConstants.BROKER_HOST, brokerHost);
templateValues.put(ContainerBasedGatewayConstants.GATEWAY_HOSTNAME, generateSubDomain(api) + "." + gatewayHostname);
ContainerBasedGatewayTemplateBuilder builder = new ContainerBasedGatewayTemplateBuilder();
// Create gateway service resource
createServiceResource(builder.generateTemplate(templateValues, ContainerBasedGatewayConstants.GATEWAY_SERVICE_TEMPLATE), serviceName);
// Create gateway deployment resource
createDeploymentResource(builder.generateTemplate(templateValues, ContainerBasedGatewayConstants.GATEWAY_DEPLOYMENT_TEMPLATE), deploymentName);
// Create gateway ingress resource
createIngressResource(builder.generateTemplate(templateValues, ContainerBasedGatewayConstants.GATEWAY_INGRESS_TEMPLATE), ingressName);
}
use of org.wso2.carbon.apimgt.api.model.subscription.API in project carbon-apimgt by wso2.
the class APIFileUtils method archiveDirectory.
/**
* Creates a zip archive from of a directory
*
* @param sourceDirectory directory to create zip archive from
* @param archiveLocation path to the archive location, excluding archive name
* @param archiveName name of the archive to create
* @throws APIMgtDAOException if an error occurs while creating the archive
*/
public static void archiveDirectory(String sourceDirectory, String archiveLocation, String archiveName) throws APIMgtDAOException {
File directoryToZip = new File(sourceDirectory);
List<File> fileList = new ArrayList<>();
getAllFiles(directoryToZip, fileList);
try {
writeArchiveFile(directoryToZip, fileList, archiveLocation, archiveName);
} catch (IOException e) {
String errorMsg = "Error while writing archive file " + directoryToZip.getPath() + " to archive " + archiveLocation;
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
if (log.isDebugEnabled()) {
log.debug("Archived API generated successfully" + archiveName);
}
}
use of org.wso2.carbon.apimgt.api.model.subscription.API in project carbon-apimgt by wso2.
the class APIFileUtils method extractUploadedArchive.
/**
* Extracts the APIs to the file system by reading the incoming {@link InputStream} object
* uploadedApiArchiveInputStream
*
* @param uploadedApiArchiveInputStream Incoming {@link InputStream}
* @param importedDirectoryName directory to extract the archive
* @param apiArchiveLocation full path of the archive location
* @param extractLocation full path to the location to which the archive will be written
* @return location to which APIs were extracted
* @throws APIMgtDAOException if an error occurs while extracting the archive
*/
public static String extractUploadedArchive(InputStream uploadedApiArchiveInputStream, String importedDirectoryName, String apiArchiveLocation, String extractLocation) throws APIMgtDAOException {
String archiveExtractLocation;
try {
// create api import directory structure
APIFileUtils.createDirectory(extractLocation);
// create archive
createArchiveFromInputStream(uploadedApiArchiveInputStream, apiArchiveLocation);
// extract the archive
archiveExtractLocation = extractLocation + File.separator + importedDirectoryName;
extractArchive(apiArchiveLocation, archiveExtractLocation);
} catch (APIMgtDAOException e) {
APIFileUtils.deleteDirectory(extractLocation);
String errorMsg = "Error in accessing uploaded API archive";
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
return archiveExtractLocation;
}
Aggregations