Search in sources :

Example 6 with Application

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

the class NodeVisitor method visit.

/**
 *     a MysqlDatabase is a service in CloudFoundry
 *     Therefore the service will be added to the application where the source of the connects to relationship is
 */
@Override
public void visit(MysqlDatabase node) {
    /*
        create service
        ignore password and port
         */
    logger.debug("Visit Mysql Database");
    Set<RootNode> sourceNodes = getSourcesOfConnectsTo(node);
    Set<Application> belongingApplication = getSourceApplications(sourceNodes);
    if (CollectionUtils.isEmpty(belongingApplication)) {
        logger.error("No source node of connects to relationship of MysqlDatabase {} was found", node.getEntityName());
        throw new TransformationFailureException("Could not find source of database");
    }
    handleStandardLifecycle(node, false, myApp);
    logger.debug("Add MYSQL service to application");
    belongingApplication.forEach(app -> app.addService(node.getEntityName(), ServiceTypes.MYSQL));
    // current application is a dummy application
    myApp.applicationIsNotReal(belongingApplication);
    // check artifacts and add paths to application
    for (Artifact artifact : node.getArtifacts()) {
        String path = artifact.getFilePath();
        myApp.addFilePath(path);
        logger.debug("Add artifact path {} to application", path);
        if (path.endsWith("sql")) {
            myApp.addConfigMysql(node.getEntityName(), path);
            logger.info("Found a SQL script in artifact paths. Will execute it with python script in deployment phase");
        }
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) TransformationFailureException(org.opentosca.toscana.plugins.util.TransformationFailureException) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) JavaApplication(org.opentosca.toscana.model.node.custom.JavaApplication) Artifact(org.opentosca.toscana.model.artifact.Artifact)

Example 7 with Application

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

the class CloudFoundryPluginTest method setUp.

@Before
public void setUp() throws Exception {
    EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    context = setUpMockTransformationContext(lamp);
    String userName = System.getenv("TEST_CF_USER");
    String pw = System.getenv("TEST_CF_PW");
    String host = System.getenv("TEST_CF_HOST");
    String space = System.getenv("TEST_CF_SPACE");
    String orga = System.getenv("TEST_CF_ORGA");
    Assume.assumeNotNull(userName, pw, host, space, orga);
    when(context.getInputs()).thenReturn(mock(PropertyInstance.class));
    when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_USERNAME)).thenReturn(userName);
    when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_PASSWORD)).thenReturn(pw);
    when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_API)).thenReturn(host);
    when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_SPACE)).thenReturn(space);
    when(context.getInputs().getOrThrow(CF_PROPERTY_KEY_ORGANIZATION)).thenReturn(orga);
    cfCycle = new CloudFoundryLifecycle(context);
    cfCycle.checkModel();
    cfCycle.prepare();
    cfCycle.fillApplications();
    File sourceDir = new File(resourcesPath, "csars/yaml/valid/lamp-noinput");
    targetDir = new File(tmpdir, "targetDir");
    sourceDir.mkdir();
    targetDir.mkdir();
    PluginFileAccess fileAccess = new PluginFileAccess(sourceDir, targetDir, logMock());
    // Set<RootNode> nodes = lamp.getNodes();
    when(context.getPluginFileAccess()).thenReturn(fileAccess);
    paths.add("app1/my_app/index.php");
    paths.add("app1/my_app/create_myphpapp.sh");
    paths.add("app1/my_db/createtable.sql");
    List<Application> applications = cfCycle.getFilledApplications();
    FileCreator fileCreator = new FileCreator(fileAccess, applications, context);
    fileCreator.createFiles();
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) PropertyInstance(org.opentosca.toscana.core.transformation.properties.PropertyInstance) File(java.io.File) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Before(org.junit.Before)

Example 8 with Application

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

the class DeploymentTest method setUp.

@Before
public void setUp() throws IOException {
    EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    this.context = setUpMockTransformationContext(lamp);
    appName = "testApp";
    testApp = new Application("testApp", 1, context);
    File sourceDir = new File(tmpdir, "sourceDir");
    targetDir = new File(tmpdir, "targetDir");
    sourceDir.mkdir();
    targetDir.mkdir();
    fileAccess = new PluginFileAccess(sourceDir, targetDir, log);
    deployScript = new BashScript(fileAccess, "deploy_" + appName);
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) BashScript(org.opentosca.toscana.plugins.scripts.BashScript) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) File(java.io.File) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Before(org.junit.Before)

Example 9 with Application

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

the class ServiceTest method checkService.

@Test
public void checkService() throws Exception {
    assumeNotNull(envUser, envHost, envOrga, envPw, envSpace);
    app.addService("my_db", ServiceTypes.MYSQL);
    List<Application> applications = new ArrayList<>();
    applications.add(app);
    fileCreator = new FileCreator(fileAccess, applications, context);
    fileCreator.createFiles();
    File targetFile = new File(targetDir, outputPath + FILEPRAEFIX_DEPLOY + deploy_name + FILESUFFIX_DEPLOY);
    String deployContent = FileUtils.readFileToString(targetFile);
    assertThat(deployContent, CoreMatchers.containsString(expectedDeployContent));
}
Also used : FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) File(java.io.File) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 10 with Application

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

the class ServiceTest method setUp.

@Before
public void setUp() throws IOException {
    EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    this.context = setUpMockTransformationContext(lamp);
    envUser = System.getenv(CF_ENVIRONMENT_USER);
    envPw = System.getenv(CF_ENVIRONMENT_PW);
    envHost = System.getenv(CF_ENVIRONMENT_HOST);
    envOrga = System.getenv(CF_ENVIRONMENT_ORGA);
    envSpace = System.getenv(CF_ENVIRONMENT_SPACE);
    app = new Application(appName, 1, context);
    app.setProvider(provider);
    connection = createConnection();
    app.setConnection(connection);
    File sourceDir = new File(tmpdir, "sourceDir");
    targetDir = new File(tmpdir, "targetDir");
    sourceDir.mkdir();
    targetDir.mkdir();
    fileAccess = new PluginFileAccess(sourceDir, targetDir, logMock());
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) File(java.io.File) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Before(org.junit.Before)

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