Search in sources :

Example 1 with Template

use of org.wso2.carbon.identity.template.mgt.model.Template in project siddhi by wso2.

the class MkdocsGitHubPagesDeployMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    // Finding the root maven project
    MavenProject rootMavenProject = mavenProject;
    while (rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }
    // Setting the relevant modules target directory if not set by user
    String moduleTargetPath;
    if (moduleTargetDirectory != null) {
        moduleTargetPath = moduleTargetDirectory.getAbsolutePath();
    } else {
        moduleTargetPath = mavenProject.getBuild().getDirectory();
    }
    // Setting the mkdocs config file path if not set by user
    if (mkdocsConfigFile == null) {
        mkdocsConfigFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.MKDOCS_CONFIG_FILE_NAME + Constants.YAML_FILE_EXTENSION);
    }
    // Setting the documentation output directory if not set by user
    String docGenBasePath;
    if (docGenBaseDirectory != null) {
        docGenBasePath = docGenBaseDirectory.getAbsolutePath();
    } else {
        docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY;
    }
    // Setting the home page file name if not set by user
    File homePageFile;
    if (homePageFileName == null) {
        homePageFile = new File(docGenBasePath + File.separator + Constants.HOMEPAGE_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    } else {
        homePageFile = new File(docGenBasePath + File.separator + homePageFileName);
    }
    // Setting the readme file name if not set by user
    if (readmeFile == null) {
        readmeFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    }
    // Setting the home page template file path if not set by user
    if (homePageTemplateFile == null) {
        homePageTemplateFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    }
    // Retrieving metadata
    List<NamespaceMetaData> namespaceMetaDataList;
    try {
        namespaceMetaDataList = DocumentationUtils.getExtensionMetaData(moduleTargetPath, mavenProject.getRuntimeClasspathElements(), getLog());
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoFailureException("Unable to resolve dependencies of the project", e);
    }
    // Generating the documentation
    if (namespaceMetaDataList.size() > 0) {
        DocumentationUtils.generateDocumentation(namespaceMetaDataList, docGenBasePath, mavenProject.getVersion(), getLog());
        DocumentationUtils.updateHeadingsInMarkdownFile(homePageTemplateFile, homePageFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
        DocumentationUtils.updateHeadingsInMarkdownFile(readmeFile, readmeFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
    }
    // Delete snapshot files
    DocumentationUtils.removeSnapshotAPIDocs(mkdocsConfigFile, docGenBasePath, getLog());
    // Updating the links in the home page to the mkdocs config
    try {
        updateAPIPagesInMkdocsConfig(mkdocsConfigFile, docGenBasePath);
    } catch (FileNotFoundException e) {
        getLog().warn("Unable to find mkdocs configuration file: " + mkdocsConfigFile.getAbsolutePath() + ". Mkdocs configuration file not updated.");
    }
    // Deploying the documentation
    if (DocumentationUtils.generateMkdocsSite(mkdocsConfigFile, getLog())) {
        // Creating the credential provider fot Git
        String scmUsername = System.getenv(Constants.SYSTEM_PROPERTY_SCM_USERNAME_KEY);
        String scmPassword = System.getenv(Constants.SYSTEM_PROPERTY_SCM_PASSWORD_KEY);
        if (scmUsername == null && scmPassword == null) {
            getLog().info("SCM_USERNAME and SCM_PASSWORD not defined!");
        }
        String url = null;
        Scm scm = rootMavenProject.getScm();
        if (scm != null) {
            url = scm.getUrl();
        }
        // Deploying documentation
        DocumentationUtils.updateDocumentationOnGitHub(docGenBasePath, mkdocsConfigFile, readmeFile, mavenProject.getVersion(), getLog());
        DocumentationUtils.deployMkdocsOnGitHubPages(mavenProject.getVersion(), rootMavenProject.getBasedir(), url, scmUsername, scmPassword, getLog());
    } else {
        getLog().warn("Unable to generate documentation. Skipping documentation deployment.");
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MavenProject(org.apache.maven.project.MavenProject) NamespaceMetaData(org.wso2.siddhi.doc.gen.commons.metadata.NamespaceMetaData) MojoFailureException(org.apache.maven.plugin.MojoFailureException) FileNotFoundException(java.io.FileNotFoundException) Scm(org.apache.maven.model.Scm) File(java.io.File)

Example 2 with Template

use of org.wso2.carbon.identity.template.mgt.model.Template in project siddhi by wso2.

the class DocumentationUtils method generateDocumentation.

/**
 * Generate documentation related files using metadata
 *
 * @param namespaceMetaDataList      Metadata in this repository
 * @param documentationBaseDirectory The path of the directory in which the documentation will be generated
 * @param documentationVersion       The version of the documentation being generated
 * @param logger                     The logger to log errors
 * @throws MojoFailureException if the Mojo fails to find template file or create new documentation file
 */
public static void generateDocumentation(List<NamespaceMetaData> namespaceMetaDataList, String documentationBaseDirectory, String documentationVersion, Log logger) throws MojoFailureException {
    // Generating data model
    Map<String, Object> rootDataModel = new HashMap<>();
    rootDataModel.put("metaData", namespaceMetaDataList);
    rootDataModel.put("formatDescription", new FormatDescriptionMethod());
    rootDataModel.put("latestDocumentationVersion", documentationVersion);
    String outputFileRelativePath = Constants.API_SUB_DIRECTORY + File.separator + documentationVersion + Constants.MARKDOWN_FILE_EXTENSION;
    generateFileFromTemplate(Constants.MARKDOWN_DOCUMENTATION_TEMPLATE + Constants.MARKDOWN_FILE_EXTENSION + Constants.FREEMARKER_TEMPLATE_FILE_EXTENSION, rootDataModel, documentationBaseDirectory, outputFileRelativePath);
    File newVersionFile = new File(documentationBaseDirectory + File.separator + outputFileRelativePath);
    File latestLabelFile = new File(documentationBaseDirectory + File.separator + Constants.API_SUB_DIRECTORY + File.separator + Constants.LATEST_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    try {
        Files.copy(newVersionFile, latestLabelFile);
    } catch (IOException e) {
        logger.warn("Failed to generate latest.md file", e);
    }
}
Also used : HashMap(java.util.HashMap) FormatDescriptionMethod(org.wso2.siddhi.doc.gen.core.freemarker.FormatDescriptionMethod) IOException(java.io.IOException) File(java.io.File)

Example 3 with Template

use of org.wso2.carbon.identity.template.mgt.model.Template in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method setApiResourceBuilderProperties.

/**
 * Extract properties in Operation entry and assign them to api resource builder properties.
 *
 * @param operationEntry     Map entry to be extracted properties
 * @param uriTemplateBuilder Uri template builder to assign related properties
 * @param resourcePath       resource path
 * @return APIResource.Builder object
 */
private APIResource.Builder setApiResourceBuilderProperties(Map.Entry<HttpMethod, Operation> operationEntry, UriTemplate.UriTemplateBuilder uriTemplateBuilder, String resourcePath) {
    Operation operation = operationEntry.getValue();
    APIResource.Builder apiResourceBuilder = new APIResource.Builder();
    List<String> producesList = operation.getProduces();
    if (producesList != null) {
        String produceSeparatedString = "\"";
        produceSeparatedString += String.join("\",\"", producesList) + "\"";
        apiResourceBuilder.produces(produceSeparatedString);
    }
    List<String> consumesList = operation.getConsumes();
    if (consumesList != null) {
        String consumesSeparatedString = "\"";
        consumesSeparatedString += String.join("\",\"", consumesList) + "\"";
        apiResourceBuilder.consumes(consumesSeparatedString);
    }
    if (operation.getOperationId() != null) {
        uriTemplateBuilder.templateId(operation.getOperationId());
    } else {
        uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(resourcePath, operationEntry.getKey().name()));
    }
    uriTemplateBuilder.httpVerb(operationEntry.getKey().name());
    apiResourceBuilder.uriTemplate(uriTemplateBuilder.build());
    return apiResourceBuilder;
}
Also used : APIResource(org.wso2.carbon.apimgt.core.models.APIResource) Operation(io.swagger.models.Operation)

Example 4 with Template

use of org.wso2.carbon.identity.template.mgt.model.Template in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createDeploymentResource.

/**
 * Create a deployment in cms
 *
 * @param deploymentTemplate Deployment template as a String
 * @param deploymentName     Name of the deployment
 * @throws ContainerBasedGatewayException if failed to create a deployment
 */
private void createDeploymentResource(String deploymentTemplate, String deploymentName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(deploymentTemplate);
    try {
        if (resource instanceof Deployment) {
            // check whether there are existing service already
            if (client.extensions().deployments().inNamespace(namespace).withName(deploymentName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Deployment resource definition: {} ", cmsType, deploymentTemplate);
                Deployment deployment = (Deployment) resource;
                Deployment result = client.extensions().deployments().inNamespace(namespace).create(deployment);
                log.info("Created Deployment : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist a deployment with the same name in " + cmsType + ". Deployment name : " + deploymentName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Deployment in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway deployment in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 5 with Template

use of org.wso2.carbon.identity.template.mgt.model.Template in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createIngressResource.

/**
 * Create an Ingress resource in cms
 *
 * @param ingressTemplate Ingress template as a String
 * @param ingressName     Name of the ingress
 * @throws ContainerBasedGatewayException if failed to create a service
 */
private void createIngressResource(String ingressTemplate, String ingressName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(ingressTemplate);
    try {
        if (resource instanceof Ingress) {
            // check whether there are existing service already
            if (client.extensions().ingresses().inNamespace(namespace).withName(ingressName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Ingress resource definition: {} ", cmsType, ingressTemplate);
                Ingress ingress = (Ingress) resource;
                Ingress result = client.extensions().ingresses().inNamespace(namespace).create(ingress);
                log.info("Created Ingress : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist an ingress with the same name in " + cmsType + ". Ingress name : " + ingressName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Service in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway ingress in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

Test (org.testng.annotations.Test)72 ArrayList (java.util.ArrayList)56 HashMap (java.util.HashMap)56 Template (org.wso2.carbon.identity.template.mgt.model.Template)46 BJSON (org.ballerinalang.model.values.BJSON)37 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)37 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)37 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)37 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)37 HashSet (java.util.HashSet)31 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)29 List (java.util.List)27 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)27 Map (java.util.Map)25 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)25 IOException (java.io.IOException)24 Connection (java.sql.Connection)24 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)24 Scope (org.wso2.carbon.apimgt.api.model.Scope)22 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)19