use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateAPIWSDLArchive.
@Override
public void updateAPIWSDLArchive(String apiId, InputStream inputStream) throws APIMgtDAOException, APIMgtWSDLException {
WSDLArchiveInfo archiveInfo = null;
InputStream fileInputStream = null;
try {
archiveInfo = extractAndValidateWSDLArchive(inputStream);
if (log.isDebugEnabled()) {
log.debug("Successfully extracted and validated WSDL file. Location: " + archiveInfo.getAbsoluteFilePath());
}
fileInputStream = new FileInputStream(archiveInfo.getAbsoluteFilePath());
getApiDAO().addOrUpdateWSDLArchive(apiId, fileInputStream, getUsername());
if (log.isDebugEnabled()) {
log.debug("Successfully updated the WSDL archive in DB. API uuid: " + apiId);
}
} catch (IOException e) {
throw new APIMgtWSDLException("Unable to process WSDL archive at " + archiveInfo.getAbsoluteFilePath(), e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
} finally {
try {
if (fileInputStream != null) {
fileInputStream.close();
}
if (archiveInfo != null) {
APIFileUtils.deleteDirectory(archiveInfo.getLocation());
}
} catch (APIMgtDAOException | IOException e) {
// This is not a blocker. Give a warning and continue
log.warn("Error occured while deleting processed WSDL artifacts folder : " + archiveInfo.getLocation());
}
}
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class FileBasedApiImportExportManager method exportAPIs.
/**
* Export a given set of APIs to the file system as a zip archive.
* The export root location is given by {@link FileBasedApiImportExportManager#path}/exported-apis.
*
* @param apiDetailSet Set of {@link APIDetails} objects to be exported
* @param exportDirectoryName Name of the directory to do the export
* @return Path to the directory with exported artifacts
* @throws APIMgtEntityImportExportException if an error occurred while exporting APIs to file system or
* no APIs are exported successfully
*/
public String exportAPIs(Set<APIDetails> apiDetailSet, String exportDirectoryName) throws APIMgtEntityImportExportException {
// this is the base directory for the archive. after export happens, this directory will
// be archived to be sent as a application/zip response to the client
String apiArtifactsBaseDirectoryPath = path + File.separator + exportDirectoryName;
try {
APIFileUtils.createDirectory(apiArtifactsBaseDirectoryPath);
} catch (APIMgtDAOException e) {
String errorMsg = "Unable to create directory for export API at :" + apiArtifactsBaseDirectoryPath;
throw new APIMgtEntityImportExportException(errorMsg, e);
}
for (APIDetails apiDetails : apiDetailSet) {
// derive the folder structure
String apiExportDirectory = APIFileUtils.getAPIBaseDirectory(apiArtifactsBaseDirectoryPath, new FileApi(apiDetails.getApi()));
API exportAPI = apiDetails.getApi();
try {
// create per-api export directory
APIFileUtils.createDirectory(apiExportDirectory);
// export API definition
APIFileUtils.exportApiDefinitionToFileSystem(new FileApi(exportAPI), apiExportDirectory);
// export swagger definition
APIFileUtils.exportSwaggerDefinitionToFileSystem(apiDetails.getSwaggerDefinition(), exportAPI, apiExportDirectory);
// export gateway configs
APIFileUtils.exportGatewayConfigToFileSystem(apiDetails.getGatewayConfiguration(), exportAPI, apiExportDirectory);
if (apiDetails.getEndpoints() != null && !apiDetails.getEndpoints().isEmpty()) {
exportEndpointsToFileSystem(apiDetails.getEndpoints(), exportAPI, apiExportDirectory);
}
} catch (APIMgtDAOException e) {
// no need to throw, log
log.error("Error in exporting API: " + exportAPI.getName() + ", version: " + apiDetails.getApi().getVersion(), e);
// cleanup the API directory
try {
APIFileUtils.deleteDirectory(path);
} catch (APIMgtDAOException e1) {
log.warn("Unable to remove directory " + path);
}
// skip this API
continue;
}
// as exported correctly.
if (apiDetails.getThumbnailStream() != null) {
try {
APIFileUtils.exportThumbnailToFileSystem(apiDetails.getThumbnailStream(), apiExportDirectory);
} catch (APIMgtDAOException warn) {
// log the warning without throwing
log.warn("Error in exporting thumbnail to file system for api: " + exportAPI.getName() + ", version: " + exportAPI.getVersion());
}
}
exportDocumentationToFileSystem(apiDetails.getAllDocumentInformation(), apiDetails, apiExportDirectory);
log.info("Successfully exported API: " + exportAPI.getName() + ", version: " + exportAPI.getVersion());
}
// if the directory is empty, no APIs have been exported!
try {
if (APIFileUtils.getDirectoryList(apiArtifactsBaseDirectoryPath).isEmpty()) {
// cleanup the archive root directory
APIFileUtils.deleteDirectory(path);
String errorMsg = "No APIs exported successfully";
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_EXPORT_ERROR);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Unable to find API definitions at: " + apiArtifactsBaseDirectoryPath;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_IMPORT_ERROR);
}
return apiArtifactsBaseDirectoryPath;
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project kubernetes by ballerinax.
the class KubernetesPlugin method process.
@Override
public void process(PackageNode packageNode) {
BLangPackage bPackage = (BLangPackage) packageNode;
KubernetesContext.getInstance().addDataHolder(bPackage.packageID, sourceDirectory.getPath());
// Get dependency jar paths
JarResolver jarResolver = KubernetesContext.getInstance().getCompilerContext().get(JAR_RESOLVER_KEY);
if (jarResolver != null) {
Set<Path> dependencyJarPaths = new HashSet<>(jarResolver.allDependencies(bPackage));
KubernetesContext.getInstance().getDataHolder(bPackage.packageID).getDockerModel().addDependencyJarPaths(dependencyJarPaths);
}
// Get the imports with alias _
List<BLangImportPackage> kubernetesImports = bPackage.getImports().stream().filter(i -> i.symbol.toString().startsWith("ballerina/kubernetes") && i.getAlias().toString().equals("_")).collect(Collectors.toList());
if (kubernetesImports.size() > 0) {
for (BLangImportPackage kubernetesImport : kubernetesImports) {
// Get the units of the file which has kubernetes import as _
List<TopLevelNode> topLevelNodes = bPackage.getCompilationUnits().stream().filter(cu -> cu.getName().equals(kubernetesImport.compUnit.getValue())).flatMap(cu -> cu.getTopLevelNodes().stream()).collect(Collectors.toList());
// Filter out the services
List<ServiceNode> serviceNodes = topLevelNodes.stream().filter(tln -> tln instanceof ServiceNode).map(tln -> (ServiceNode) tln).collect(Collectors.toList());
// Generate artifacts for services for all services
serviceNodes.forEach(sn -> process(sn, Collections.singletonList(createAnnotation("Deployment"))));
// Create Service annotation with NodePort service type
AnnotationAttachmentNode serviceAnnotation = createAnnotation("Service");
BLangRecordLiteral svcRecordLiteral = (BLangRecordLiteral) TreeBuilder.createRecordLiteralNode();
serviceAnnotation.setExpression(svcRecordLiteral);
BLangLiteral serviceTypeKey = (BLangLiteral) TreeBuilder.createLiteralExpression();
serviceTypeKey.value = ServiceAnnotationProcessor.ServiceConfiguration.serviceType.name();
serviceTypeKey.type = new BType(TypeTags.STRING, null);
BLangLiteral serviceTypeValue = new BLangLiteral();
serviceTypeValue.value = KubernetesConstants.ServiceType.NodePort.name();
serviceTypeValue.type = new BType(TypeTags.STRING, null);
BLangRecordLiteral.BLangRecordKeyValueField serviceTypeRecordField = new BLangRecordLiteral.BLangRecordKeyValueField();
serviceTypeRecordField.key = new BLangRecordLiteral.BLangRecordKey(serviceTypeKey);
serviceTypeRecordField.valueExpr = serviceTypeValue;
svcRecordLiteral.fields.add(serviceTypeRecordField);
// Filter services with 'new Listener()' and generate services
for (ServiceNode serviceNode : serviceNodes) {
Optional<? extends ExpressionNode> initListener = serviceNode.getAttachedExprs().stream().filter(aex -> aex instanceof BLangTypeInit).findAny();
if (initListener.isPresent()) {
serviceNodes.forEach(sn -> process(sn, Collections.singletonList(serviceAnnotation)));
}
}
// Get the variable names of the listeners attached to services
List<String> listenerNamesToExpose = serviceNodes.stream().map(ServiceNode::getAttachedExprs).flatMap(Collection::stream).filter(aex -> aex instanceof BLangSimpleVarRef).map(aex -> (BLangSimpleVarRef) aex).map(BLangSimpleVarRef::toString).collect(Collectors.toList());
// Generate artifacts for listeners attached to services
topLevelNodes.stream().filter(tln -> tln instanceof SimpleVariableNode).map(tln -> (SimpleVariableNode) tln).filter(listener -> listenerNamesToExpose.contains(listener.getName().getValue())).forEach(listener -> process(listener, Collections.singletonList(serviceAnnotation)));
// Generate artifacts for main functions
topLevelNodes.stream().filter(tln -> tln instanceof FunctionNode).map(tln -> (FunctionNode) tln).filter(fn -> "main".equals(fn.getName().getValue())).forEach(fn -> process(fn, Collections.singletonList(createAnnotation("Job"))));
}
}
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-business-process by wso2.
the class BPELAppDeployer method undeployArtifacts.
/**
* Check the artifact type and if it is a BPEL, delete the file from the BPEL
* deployment hot folder
*
* @param carbonApp - CarbonApplication instance to check for BPEL artifacts
* @param axisConfig - - axisConfig of the current tenant
*/
public void undeployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) {
List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
for (Artifact.Dependency dep : artifacts) {
Deployer deployer;
Artifact artifact = dep.getArtifact();
if (artifact == null) {
continue;
}
if (BPEL_TYPE.equals(artifact.getType())) {
deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, BPEL_DIR, "zip");
} else {
continue;
}
// loop through all dependencies
List<CappFile> files = artifact.getFiles();
if (files.size() != 1) {
log.error("A BPEL workflow must have a single file. But " + files.size() + " files found.");
continue;
}
if (deployer != null && AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED.equals(artifact.getDeploymentStatus())) {
String fileName = artifact.getFiles().get(0).getName();
String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
try {
File artifactFile = new File(artifactPath);
if (artifactFile.exists() && !artifactFile.delete()) {
log.warn("Couldn't delete App artifact file : " + artifactPath);
}
deployer.undeploy(artifactPath);
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_PENDING);
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
log.error("Error occured while trying to un deploy : " + artifact.getName());
}
}
}
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-business-process by wso2.
the class BPELAppDeployer method deployArtifacts.
/**
* Check the artifact type and if it is a BPEL, copy it to the BPEL deployment hot folder
*
* @param carbonApp - CarbonApplication instance to check for BPEL artifacts
* @param axisConfig - AxisConfiguration of the current tenant
*/
public void deployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) throws DeploymentException {
List<Artifact.Dependency> artifacts = carbonApp.getAppConfig().getApplicationArtifact().getDependencies();
// loop through all artifacts
for (Artifact.Dependency dep : artifacts) {
Deployer deployer;
Artifact artifact = dep.getArtifact();
if (artifact == null) {
continue;
}
if (!isAccepted(artifact.getType())) {
log.warn("Can't deploy artifact : " + artifact.getName() + " of type : " + artifact.getType() + ". Required features are not installed in the system");
continue;
}
if (BPEL_TYPE.equals(artifact.getType())) {
deployer = AppDeployerUtils.getArtifactDeployer(axisConfig, BPEL_DIR, "zip");
} else {
continue;
}
List<CappFile> files = artifact.getFiles();
if (files.size() != 1) {
log.error("BPEL workflows must have a single file to " + "be deployed. But " + files.size() + " files found.");
continue;
}
if (deployer != null) {
String fileName = artifact.getFiles().get(0).getName();
String artifactPath = artifact.getExtractedPath() + File.separator + fileName;
try {
deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer));
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED);
} catch (DeploymentException e) {
artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);
throw e;
}
}
}
}
Aggregations