use of org.wso2.carbon.apimgt.core.models.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.core.models.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.core.models.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.core.models.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;
}
use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.
the class APIThrottlePolicyTemplateBuilder method getThrottlePolicyTemplateForPipelines.
/**
* Generate policy for api level throttling
*
* @return throttle policies for api level
* @throws APITemplateException throws if generation failure occur
*/
public Map<String, String> getThrottlePolicyTemplateForPipelines() throws APITemplateException {
if (log.isDebugEnabled()) {
log.debug("Generating Siddhi App for apiLevel :" + apiPolicy.toString());
}
// get velocity template for API policy pipeline and generate the template
Map<String, String> policyArray = new HashMap<String, String>();
StringWriter writer;
VelocityContext context;
VelocityEngine velocityengine = initVelocityEngine();
Template template = velocityengine.getTemplate(getTemplatePathForAPI());
// Generate template for pipeline conditions if pipelines not null
if (apiPolicy.getPipelines() != null) {
for (Pipeline pipeline : apiPolicy.getPipelines()) {
// set values for velocity context
context = new VelocityContext();
setConstantContext(context);
context.put(PIPELINE_ITEM, pipeline);
context.put(POLICY, apiPolicy);
context.put(QUOTA_POLICY, pipeline.getQuotaPolicy());
context.put(PIPELINE, CONDITION + UNDERSCORE + pipeline.getId());
String conditionString = getPolicyCondition(pipeline.getConditions());
context.put(CONDITION, AND + conditionString);
writer = new StringWriter();
template.merge(context, writer);
if (log.isDebugEnabled()) {
log.debug("Generated Siddhi App : " + writer.toString());
}
String policyName = PolicyConstants.POLICY_LEVEL_RESOURCE + UNDERSCORE + apiPolicy.getPolicyName() + UNDERSCORE + CONDITION + UNDERSCORE + pipeline.getId();
policyArray.put(policyName, writer.toString());
}
}
return policyArray;
}
Aggregations