Search in sources :

Example 16 with Application

use of org.opentosca.toscana.plugins.cloudfoundry.application.Application in project TOSCAna by StuPro-TOSCAna.

the class CloudFoundryLifecycle method prepare.

@Override
public void prepare() {
    logger.info("Begin preparation for transformation to Cloud Foundry");
    PrepareVisitor prepareVisitor = new PrepareVisitor(logger);
    for (RootNode node : context.getModel().getNodes()) {
        node.accept(prepareVisitor);
    }
    logger.debug("Collecting Compute Nodes in topology");
    ComputeNodeFindingVisitor computeFinder = new ComputeNodeFindingVisitor();
    model.getNodes().forEach(e -> {
        e.accept(computeFinder);
        KubernetesNodeContainer container = new KubernetesNodeContainer(e);
        nodes.put(e.getEntityName(), container);
    });
    computeFinder.getComputeNodes().forEach(e -> computeNodes.add(nodes.get(e.getEntityName())));
    logger.debug("Finding top Level Nodes");
    graph = model.getTopology();
    Set<RootNode> topLevelNodes = determineTopLevelNodes(context.getModel(), computeFinder.getComputeNodes().stream().map(Compute.class::cast).collect(Collectors.toList()), e -> nodes.get(e.getEntityName()).activateParentComputeNode());
    logger.debug("Building complete Topology stacks");
    this.stacks.addAll(buildTopologyStacks(model, topLevelNodes, nodes));
    // TODO: check how many different applications there are and fill list with them
    // probably there must be a combination of application and set of nodes
    applications = new ArrayList<>();
    int i = 1;
    for (NodeStack stack : stacks) {
        Application myApp = new Application(i, context);
        i++;
        myApp.setProvider(provider);
        myApp.setConnection(connection);
        myApp.setName(stack.getStackName());
        myApp.addStack(stack);
        applications.add(myApp);
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Compute(org.opentosca.toscana.model.node.Compute) KubernetesNodeContainer(org.opentosca.toscana.plugins.kubernetes.util.KubernetesNodeContainer) NodeStack(org.opentosca.toscana.plugins.kubernetes.util.NodeStack) ComputeNodeFindingVisitor(org.opentosca.toscana.plugins.kubernetes.visitor.util.ComputeNodeFindingVisitor) PrepareVisitor(org.opentosca.toscana.plugins.cloudfoundry.visitor.PrepareVisitor) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application)

Example 17 with Application

use of org.opentosca.toscana.plugins.cloudfoundry.application.Application in project TOSCAna by StuPro-TOSCAna.

the class ApplicationHandler method handleApplications.

/**
 *     check applications if they are "real" applications or just dummies like services
 *     copies data from the dummy application to the application which it belongs to.
 *
 *     @return a list with only real applications with all needed data
 */
List<Application> handleApplications() {
    List<Application> checkedApplications = new ArrayList<>();
    List<Application> realApplications = uncheckedApplications.stream().filter(Application::isRealApplication).collect(Collectors.toList());
    // set new application number because the dummy applications are missing
    for (int i = 0; i < realApplications.size(); i++) {
        realApplications.get(i).setApplicationNumber(i + 1);
    }
    // sort checked applications by application number
    realApplications.sort(Comparator.comparing(Application::getApplicationNumber));
    for (Application application : uncheckedApplications) {
        if (!application.isRealApplication()) {
            Set<Application> parentApplications = application.getParentApplications();
            if (CollectionUtils.isNotEmpty(parentApplications)) {
                parentApplications.forEach(parentApplication -> copyData(application, parentApplication));
            } else {
                logger.error("There is a unreal application like a service, but no parent application");
            }
        } else {
            checkedApplications.add(application);
            logger.debug("Checked application {}", application.getName());
        }
    }
    return checkedApplications;
}
Also used : ArrayList(java.util.ArrayList) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application)

Example 18 with Application

use of org.opentosca.toscana.plugins.cloudfoundry.application.Application in project TOSCAna by StuPro-TOSCAna.

the class FileCreator method createReadme.

/**
 *     create a readme for a transformation. Inserts the application names.
 */
private void createReadme() throws IOException {
    Class fileCreatorClass = FileCreator.class;
    String README_SOURCE = "/cloudFoundry/readme.txt";
    String REAMDE_FILENAME = "README.txt";
    InputStream inputStream = fileCreatorClass.getResourceAsStream(README_SOURCE);
    String contentFile = IOUtils.toString(inputStream);
    inputStream.close();
    logger.debug("Add application folder names to readme");
    String applicationList = "";
    for (Application application : applications) {
        applicationList = applicationList + "  - app" + application.getApplicationNumber() + "\n";
    }
    contentFile = contentFile.replaceAll("application_names", applicationList);
    fileAccess.access(OUTPUT_DIR + REAMDE_FILENAME).appendln(contentFile).close();
}
Also used : InputStream(java.io.InputStream) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application)

Example 19 with Application

use of org.opentosca.toscana.plugins.cloudfoundry.application.Application in project TOSCAna by StuPro-TOSCAna.

the class FileCreator method createDeployScript.

/**
 *     creates a deploy shell script
 */
private void createDeployScript() throws IOException {
    if (applications.size() > 1) {
        deploy_name += "s";
    }
    BashScript deployScript = new BashScript(fileAccess, FILEPRAEFIX_DEPLOY + deploy_name);
    deployScript.append("echo \"$(tput bold)--------TOSCAna Cloud Foundry deployment--------$(tput sgr0)\"");
    deployScript.append("echo \"This script will deploy your application to the Cloud Foundry instance\"");
    deployScript.append("echo \"We use the CloudFoundry CLI and show you the output as well\"");
    deployScript.append("echo \"Is there no CF CLI installed we have to stop, we will check it\"");
    deployScript.append("echo \"We will deploy the application to the connected provider\"");
    deployScript.append("echo \"If you use a Cloud Foundry service with your application, " + "you are able to change the service or plan in this deploy script manually\"");
    deployScript.append("echo \"We tried to choose a suitable service with a free plan\"");
    deployScript.append("echo \"You could check all possible services in the file$(tput bold) " + SERVICE_FILE_PATH + " $(tput sgr0)\"");
    deployScript.append("echo \"$(tput bold)--------TOSCAna Cloud Foundry deployment$(tput sgr0)--------\n\"");
    deployScript.append(EnvironmentCheck.checkEnvironment("cf"));
    // handle services
    logger.debug("Handle services");
    handleServices(deployScript);
    // replace
    logger.debug("Replace strings");
    replaceStrings(deployScript);
    // push applications
    for (Application application : applications) {
        deployScript.append(CLI_PUSH + application.getName() + CLI_PATH_TO_MANIFEST + MANIFEST_NAME + CLI_NO_START);
    }
    // read credentials, replace, executeScript, configureMysql
    for (Application application : applications) {
        Deployment deployment = new Deployment(deployScript, application, fileAccess, context);
        // read credentials
        readCredentials(deployment, application);
        // configureSql
        configureSql(deployment, application);
        // start application
        deployScript.append(CLI_START + application.getName());
        // execute
        executeFiles(deployment, application);
    }
    deployScript.append("echo \"\n\n$(tput bold)The deployment of your application is finished. You see the urls of your apps here:$(tput sgr0)\n\"");
    deployScript.append("cf routes");
}
Also used : BashScript(org.opentosca.toscana.plugins.scripts.BashScript) Deployment(org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application)

Aggregations

Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)19 File (java.io.File)9 ArrayList (java.util.ArrayList)7 FileCreator (org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator)7 Test (org.junit.Test)5 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)5 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)5 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)5 WebApplication (org.opentosca.toscana.model.node.WebApplication)5 Before (org.junit.Before)4 PluginFileAccess (org.opentosca.toscana.core.plugin.PluginFileAccess)4 RootNode (org.opentosca.toscana.model.node.RootNode)3 Deployment (org.opentosca.toscana.plugins.cloudfoundry.application.deployment.Deployment)3 KubernetesNodeContainer (org.opentosca.toscana.plugins.kubernetes.util.KubernetesNodeContainer)2 BashScript (org.opentosca.toscana.plugins.scripts.BashScript)2 InputStream (java.io.InputStream)1 Map (java.util.Map)1 PropertyInstance (org.opentosca.toscana.core.transformation.properties.PropertyInstance)1 Artifact (org.opentosca.toscana.model.artifact.Artifact)1 Compute (org.opentosca.toscana.model.node.Compute)1