use of org.opentosca.toscana.model.artifact.Artifact 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());
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class LinkResolverTest method resolveImplementationLink.
@Test
public void resolveImplementationLink() {
EffectiveModel model = new EffectiveModelFactory().create(ARTIFACT, logMock());
WebServer node = (WebServer) model.getNodeMap().get("test-node");
Optional<Operation> create = node.getStandardLifecycle().getCreate();
assertTrue(create.isPresent());
Optional<Artifact> artifact = create.get().getArtifact();
assertTrue(artifact.isPresent());
assertEquals("test-file", artifact.get().getFilePath());
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class NodeConvertTest method java.
@Test
public void java() {
EffectiveModel model = new EffectiveModelFactory().create(JAVA, logMock());
JavaApplication app = (JavaApplication) model.getNodeMap().get("app");
assertEquals("test-vm_options", app.getVmOptions().get());
assertEquals("test-arguments", app.getArguments().get());
Artifact artifact = app.getJar();
assertEquals("test-artifact-path", artifact.getFilePath());
JavaRuntime jre = (JavaRuntime) model.getNodeMap().get("jre");
assertEquals("1.8", jre.getComponentVersion().get());
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class TransformModelNodeVisitor method visit.
@Override
public void visit(MysqlDatabase node) {
try {
String nodeName = toAlphanumerical(node.getEntityName());
// get the compute where the dbms this node is hosted on, is hosted on
Compute compute = getCompute(node);
String serverName = toAlphanumerical(compute.getEntityName());
String dbName = node.getDatabaseName();
String masterUser = node.getUser().orElseThrow(() -> new IllegalArgumentException("Database user not set"));
String masterPassword = node.getPassword().orElseThrow(() -> new IllegalArgumentException("Database " + "password not set"));
Integer port = node.getPort().orElseThrow(() -> new IllegalArgumentException("Database port not set"));
// check what values should be taken
ComputeCapability hostedOnComputeCapability = compute.getHost();
CapabilityMapper capabilityMapper = createCapabilityMapper();
String dBInstanceClass = capabilityMapper.mapComputeCapabilityToInstanceType(hostedOnComputeCapability, CapabilityMapper.RDS_DISTINCTION);
Integer allocatedStorage = capabilityMapper.mapComputeCapabilityToRDSAllocatedStorage(hostedOnComputeCapability);
// SSD
String storageType = "gp2";
String securityGroupName = nodeName + SECURITY_GROUP;
SecurityGroup securityGroup = cfnModule.resource(SecurityGroup.class, securityGroupName).groupDescription("Open database " + dbName + " for access to group " + serverName + SECURITY_GROUP);
Set<Compute> hostsOfConnectedTo = getHostsOfConnectedTo(node);
for (Compute hostOfConnectedTo : hostsOfConnectedTo) {
securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(hostOfConnectedTo.getEntityName()) + SECURITY_GROUP)), PROTOCOL_TCP, port);
}
cfnModule.resource(DBInstance.class, nodeName).engine("MySQL").dBName(dbName).masterUsername(masterUser).masterUserPassword(masterPassword).dBInstanceClass(dBInstanceClass).allocatedStorage(allocatedStorage).storageType(storageType).vPCSecurityGroups(cfnModule.fnGetAtt(securityGroupName, "GroupId"));
// handle sql artifact
for (Artifact artifact : node.getArtifacts()) {
String relPath = artifact.getFilePath();
if (relPath.endsWith(".sql")) {
String sql = cfnModule.getFileAccess().read(artifact.getFilePath());
String computeName = createSqlCompute(node, sql);
securityGroup.ingress(ingress -> ingress.sourceSecurityGroupName(cfnModule.ref(toAlphanumerical(computeName) + SECURITY_GROUP)), PROTOCOL_TCP, port);
}
}
} catch (Exception e) {
logger.error("Error while creating MysqlDatabase resource.");
throw new TransformationFailureException("Failed at MysqlDatabase node " + node.getEntityName(), e);
}
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class NodeVisitor method getScripts.
private void getScripts(RootNode node, Application application) {
StandardLifecycle lifecycle = node.getStandardLifecycle();
Optional<Operation> configureOptional = lifecycle.getConfigure();
// get configure script
if (configureOptional.isPresent()) {
Optional<Artifact> configureArtifact = configureOptional.get().getArtifact();
configureArtifact.ifPresent(artifact -> application.addExecuteFile(artifact.getFilePath(), node));
}
// get create script
Optional<Operation> createOptional = lifecycle.getCreate();
if (createOptional.isPresent()) {
Optional<Artifact> createArtifact = createOptional.get().getArtifact();
createArtifact.ifPresent(artifact -> application.addExecuteFile(artifact.getFilePath(), node));
}
}
Aggregations