Search in sources :

Example 1 with WebApplication

use of org.opentosca.toscana.model.node.WebApplication in project TOSCAna by StuPro-TOSCAna.

the class CheckModelRelationshipVisitor method visit.

@Override
public void visit(ConnectsTo relation) {
    RootNode source = topology.getEdgeSource(relation);
    RootNode target = topology.getEdgeTarget(relation);
    if (!(source instanceof WebApplication && target instanceof Database)) {
        throw new UnsupportedTypeException("ConnectsTo relationship from source: " + source + " to target: " + target + " not supported.");
    }
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) Database(org.opentosca.toscana.model.node.Database) UnsupportedTypeException(org.opentosca.toscana.model.visitor.UnsupportedTypeException) WebApplication(org.opentosca.toscana.model.node.WebApplication)

Example 2 with WebApplication

use of org.opentosca.toscana.model.node.WebApplication in project TOSCAna by StuPro-TOSCAna.

the class GraphNormalizerTest method artifactNormalization.

@Test
public void artifactNormalization() {
    ServiceGraph graph = new ServiceGraph(ARTIFACT, logMock());
    EntityId nodeId = ToscaStructure.NODE_TEMPLATES.descend("test-node");
    Entity nodeEntity = graph.getEntityOrThrow(nodeId);
    WebApplication webApplication = new TypeWrapper().wrapEntity((MappingEntity) nodeEntity, WebApplication.class);
    Artifact artifact = webApplication.getArtifacts().iterator().next();
    assertEquals("test-artifact", artifact.getEntityName());
    assertEquals("test-artifact-file", artifact.getFilePath());
}
Also used : EntityId(org.opentosca.toscana.model.EntityId) ScalarEntity(org.opentosca.toscana.core.parse.model.ScalarEntity) Entity(org.opentosca.toscana.core.parse.model.Entity) MappingEntity(org.opentosca.toscana.core.parse.model.MappingEntity) ServiceGraph(org.opentosca.toscana.core.parse.model.ServiceGraph) WebApplication(org.opentosca.toscana.model.node.WebApplication) Artifact(org.opentosca.toscana.model.artifact.Artifact) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 3 with WebApplication

use of org.opentosca.toscana.model.node.WebApplication in project TOSCAna by StuPro-TOSCAna.

the class DataTypeTest method portTest.

@Test
public void portTest() {
    EffectiveModel model = new EffectiveModelFactory().create(TestTemplates.Datatypes.PORT, logMock());
    WebApplication app = (WebApplication) model.getNodes().iterator().next();
    EndpointCapability endpoint = app.getAppEndpoint();
    assertEquals(new Port(3000), endpoint.getPort().get());
    Port expected = new Port(4000);
    endpoint.setPort(expected);
    assertEquals(expected, endpoint.getPort().get());
}
Also used : Port(org.opentosca.toscana.model.datatype.Port) WebApplication(org.opentosca.toscana.model.node.WebApplication) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 4 with WebApplication

use of org.opentosca.toscana.model.node.WebApplication in project TOSCAna by StuPro-TOSCAna.

the class DynamicRequirementTest method dynamicRequirementTest.

@Test
public void dynamicRequirementTest() {
    EffectiveModel model = new EffectiveModelFactory().create(TestTemplates.Requirements.DYNAMIC_REQUIREMENT, logMock());
    WebApplication app = (WebApplication) model.getNodes().iterator().next();
    Requirement<? extends Capability, ? extends RootNode, ? extends RootRelationship> dynamicRequirement = app.getRequirements().stream().filter(r -> "dynamic-requirement".equals(r.getEntityName())).findFirst().orElseThrow(() -> new IllegalStateException("dynamic requirement should exist"));
    RootRelationship relationship = dynamicRequirement.getRelationship().get();
    assertEquals(ConnectsTo.class, relationship.getClass());
    Capability capability = dynamicRequirement.get(dynamicRequirement.CAPABILITY);
    assertEquals(EndpointCapability.class, capability.getClass());
    RootNode fulfiller = dynamicRequirement.getFulfillers().iterator().next();
    assertEquals(app, fulfiller);
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) EndpointCapability(org.opentosca.toscana.model.capability.EndpointCapability) Capability(org.opentosca.toscana.model.capability.Capability) WebApplication(org.opentosca.toscana.model.node.WebApplication) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) RootRelationship(org.opentosca.toscana.model.relation.RootRelationship) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 5 with WebApplication

use of org.opentosca.toscana.model.node.WebApplication in project TOSCAna by StuPro-TOSCAna.

the class FileCreatorTest method checkMultipleApplicationServices.

@Test
public void checkMultipleApplicationServices() throws IOException, JSONException {
    String serviceName = "mydb";
    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);
    connection = createConnection();
    Application app = new Application("app", 1, context);
    Application secondApp = new Application("appSec", 2, context);
    app.setProvider(new Provider(Provider.CloudFoundryProviderType.PIVOTAL));
    app.setConnection(connection);
    secondApp.setProvider(new Provider(Provider.CloudFoundryProviderType.PIVOTAL));
    secondApp.setConnection(connection);
    app.addService(service1, ServiceTypes.MYSQL);
    secondApp.addService(serviceName, ServiceTypes.MYSQL);
    EffectiveModel lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    RootNode webApplicationNode = null;
    RootNode mysqlDatabaseNode = null;
    for (RootNode node : lamp.getNodes()) {
        if (node instanceof WebApplication) {
            webApplicationNode = node;
        }
        if (node instanceof MysqlDatabase) {
            mysqlDatabaseNode = node;
        }
    }
    app.addConfigMysql(service1, "my_db/configSql.sql");
    app.addExecuteFile("my_app/configure_myphpapp.sh", webApplicationNode);
    secondApp.addConfigMysql(serviceName, "database/config.sql");
    secondApp.addExecuteFile("database/dbinit.sh", mysqlDatabaseNode);
    List<Application> applications = new ArrayList<>();
    applications.add(app);
    applications.add(secondApp);
    FileCreator fileCreator = new FileCreator(fileAccess, applications, context);
    fileCreator.createFiles();
    File targetFile = new File(targetDir, outputPath + FILEPRAEFIX_DEPLOY + deploy_name + FILESUFFIX_DEPLOY);
    String deployscriptContent = FileUtils.readFileToString(targetFile);
    String expectedContent = "check python\n" + "python replace.py ../../app1/my_app/configure_myphpapp.sh /var/www/html/ /home/vcap/app/htdocs/\n" + "python replace.py ../../app2/database/dbinit.sh /var/www/html/ /home/vcap/app/htdocs/\n" + "cf push app -f ../manifest.yml --no-start\n" + "cf push appSec -f ../manifest.yml --no-start\n" + "python readCredentials.py app cleardb mysql cleardb\n" + "python configureMysql.py ../../app1/my_db/configSql.sql\n" + "cf start app\n" + "python executeCommand.py app /home/vcap/app/htdocs/my_app/configure_myphpapp.sh\n" + "python readCredentials.py appSec cleardb mysql mydb\n" + "python configureMysql.py ../../app2/database/config.sql\n" + "cf start appSec\n" + "python executeCommand.py appSec /home/vcap/app/database/dbinit.sh\n";
    assertTrue(deployscriptContent.contains(expectedContent));
// assertEquals(expectedContent, deployscriptContent);
}
Also used : RootNode(org.opentosca.toscana.model.node.RootNode) MysqlDatabase(org.opentosca.toscana.model.node.MysqlDatabase) FileCreator(org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator) ArrayList(java.util.ArrayList) WebApplication(org.opentosca.toscana.model.node.WebApplication) Application(org.opentosca.toscana.plugins.cloudfoundry.application.Application) WebApplication(org.opentosca.toscana.model.node.WebApplication) File(java.io.File) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) Provider(org.opentosca.toscana.plugins.cloudfoundry.application.Provider) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Aggregations

WebApplication (org.opentosca.toscana.model.node.WebApplication)7 RootNode (org.opentosca.toscana.model.node.RootNode)5 Test (org.junit.Test)4 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)4 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)3 EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)3 EndpointCapability (org.opentosca.toscana.model.capability.EndpointCapability)2 Compute (org.opentosca.toscana.model.node.Compute)2 MysqlDatabase (org.opentosca.toscana.model.node.MysqlDatabase)2 RootRelationship (org.opentosca.toscana.model.relation.RootRelationship)2 Fn (com.scaleset.cfbuilder.core.Fn)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Entity (org.opentosca.toscana.core.parse.model.Entity)1 MappingEntity (org.opentosca.toscana.core.parse.model.MappingEntity)1 ScalarEntity (org.opentosca.toscana.core.parse.model.ScalarEntity)1 ServiceGraph (org.opentosca.toscana.core.parse.model.ServiceGraph)1 EntityId (org.opentosca.toscana.model.EntityId)1 Artifact (org.opentosca.toscana.model.artifact.Artifact)1