Search in sources :

Example 31 with EffectiveModelFactory

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

the class TemplateConverterTest method taskTranslatorConverter.

@Test
public void taskTranslatorConverter() {
    EffectiveModel model = new EffectiveModelFactory().create(TestCsars.VALID_TASKTRANSLATOR_TEMPLATE, logMock());
    assertNotNull(model);
}
Also used : EffectiveModel(org.opentosca.toscana.model.EffectiveModel) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BaseUnitTest(org.opentosca.toscana.core.BaseUnitTest) Test(org.junit.Test)

Example 32 with EffectiveModelFactory

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

the class TransformationDaoUnitTest method setUp.

@Before
public void setUp() throws IOException, InvalidCsarException {
    when(platformService.findPlatformById(PLATFORM1.id)).thenReturn(Optional.ofNullable(PLATFORM1));
    when(preferences.getDataDir()).thenReturn(tmpdir);
    Log log = logMock();
    csar = spy(new CsarImpl(new File(""), "csarIdentifier", log));
    doReturn(new File("")).when(csar).getTemplate();
    File csarTransformationDir = new File(tmpdir, "transformationDir");
    csarTransformationDir.mkdir();
    when(csarDao.getTransformationsDir(csar)).thenReturn(csarTransformationDir);
    platformDir = new File(csarTransformationDir, PLATFORM1.id);
    platformDir.mkdir();
    File someTransformationFile = new File(platformDir, "some-file");
    someTransformationFile.createNewFile();
    EffectiveModelFactory modelFactory = mock(EffectiveModelFactory.class);
    EffectiveModel model = modelMock();
    when(modelFactory.create(any(File.class), any(Log.class))).thenReturn(model);
    dao = new TransformationFilesystemDao(platformService, modelFactory);
    dao.setCsarDao(csarDao);
}
Also used : Log(org.opentosca.toscana.core.transformation.logging.Log) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) File(java.io.File) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) Before(org.junit.Before)

Example 33 with EffectiveModelFactory

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

the class TransformationFilesystemDaoTest method setUp.

@Before
public void setUp() throws InvalidCsarException {
    csar = spy(new CsarImpl(new File(""), "csar1", logMock()));
    doReturn(new File("")).when(csar).getTemplate();
    EffectiveModelFactory modelFactory = mock(EffectiveModelFactory.class);
    EffectiveModel model = modelMock();
    when(modelFactory.create(any(File.class), any(Log.class))).thenReturn(model);
    transformationDao = new TransformationFilesystemDao(platformService, modelFactory);
    transformationDao.setCsarDao(csarDao);
    transformation = new TransformationImpl(csar, PLATFORM1, logMock(), modelMock());
    transformationRootDir = transformationDao.getRootDir(transformation);
}
Also used : Log(org.opentosca.toscana.core.transformation.logging.Log) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) File(java.io.File) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) EffectiveModel(org.opentosca.toscana.model.EffectiveModel) Before(org.junit.Before)

Example 34 with EffectiveModelFactory

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

the class CloudFormationPluginTest method setUp.

@Before
public void setUp() throws Exception {
    lamp = new EffectiveModelFactory().create(TestCsars.VALID_LAMP_NO_INPUT_TEMPLATE, logMock());
    fileAccess = new PluginFileAccess(new File("src/test/resources/csars/yaml/valid/lamp-input/"), tmpdir, logMock());
    cfnModule = new CloudFormationModule(fileAccess, "us-west-2", new BasicAWSCredentials("", ""));
    TransformationContext context = mock(TransformationContext.class);
    when(context.getModel()).thenReturn(lamp);
    when(context.getLogger((Class<?>) any(Class.class))).thenReturn(LoggerFactory.getLogger("Dummy Logger"));
    TransformModelNodeVisitor cfnNodeVisitorL = new TransformModelNodeVisitor(context, cfnModule);
    cfnNodeVisitor = spy(cfnNodeVisitorL);
    CapabilityMapper capabilityMapper = mock(CapabilityMapper.class);
    when(capabilityMapper.mapOsCapabilityToImageId(any(OsCapability.class))).thenReturn("ami-testami");
    when(cfnNodeVisitor.createCapabilityMapper()).thenReturn(capabilityMapper);
}
Also used : PluginFileAccess(org.opentosca.toscana.core.plugin.PluginFileAccess) OsCapability(org.opentosca.toscana.model.capability.OsCapability) TransformModelNodeVisitor(org.opentosca.toscana.plugins.cloudformation.visitor.TransformModelNodeVisitor) File(java.io.File) TransformationContext(org.opentosca.toscana.core.transformation.TransformationContext) CapabilityMapper(org.opentosca.toscana.plugins.cloudformation.mapper.CapabilityMapper) EffectiveModelFactory(org.opentosca.toscana.model.EffectiveModelFactory) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Before(org.junit.Before)

Example 35 with EffectiveModelFactory

use of org.opentosca.toscana.model.EffectiveModelFactory 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

EffectiveModelFactory (org.opentosca.toscana.model.EffectiveModelFactory)37 EffectiveModel (org.opentosca.toscana.model.EffectiveModel)31 Test (org.junit.Test)25 BaseUnitTest (org.opentosca.toscana.core.BaseUnitTest)22 File (java.io.File)10 Before (org.junit.Before)10 PluginFileAccess (org.opentosca.toscana.core.plugin.PluginFileAccess)6 Database (org.opentosca.toscana.model.node.Database)5 Application (org.opentosca.toscana.plugins.cloudfoundry.application.Application)5 WebApplication (org.opentosca.toscana.model.node.WebApplication)4 BaseSpringTest (org.opentosca.toscana.core.BaseSpringTest)3 Csar (org.opentosca.toscana.core.csar.Csar)3 Log (org.opentosca.toscana.core.transformation.logging.Log)3 Artifact (org.opentosca.toscana.model.artifact.Artifact)3 RootNode (org.opentosca.toscana.model.node.RootNode)3 WebServer (org.opentosca.toscana.model.node.WebServer)3 FileCreator (org.opentosca.toscana.plugins.cloudfoundry.filecreator.FileCreator)3 ArrayList (java.util.ArrayList)2 CsarImpl (org.opentosca.toscana.core.csar.CsarImpl)2 TransformationContext (org.opentosca.toscana.core.transformation.TransformationContext)2