use of org.opentosca.toscana.model.artifact.Artifact 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");
}
}
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class LinkResolver method resolveRepositories.
private static void resolveRepositories(ServiceGraph graph) {
logger.debug(LogFormat.indent(1, "repositories"));
Map<String, RootNode> nodes = new TypeWrapper().wrapNodes(graph);
for (RootNode node : nodes.values()) {
for (Artifact artifact : node.getArtifacts()) {
MappingEntity artifactEntity = artifact.getBackingEntity();
Optional<Entity> repository = artifactEntity.getChild(Artifact.REPOSITORY.name);
if (repository.isPresent()) {
String url = ((ScalarEntity) repository.get()).getValue();
EntityId targetId = ToscaStructure.REPOSITORIES.descend(url);
Optional<Entity> target = graph.getEntity(targetId);
target.ifPresent(baseEntity -> {
logger.debug(LogFormat.pointAt(2, repository.get().getId(), baseEntity.getId()));
graph.replaceEntity(repository.get(), baseEntity);
});
}
}
}
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class DockerfileBuildingVisitor method visit.
@Override
public void visit(MysqlDatabase node) {
builder.env(ENV_KEY_MYSQL_DATABASE, node.getDatabaseName());
if (node.getUser().isPresent() && !node.getUser().get().equals("root")) {
builder.env(ENV_KEY_MYSQL_USER, node.getUser().get());
builder.env(ENV_KEY_MYSQL_PASSWORD, node.getPassword().orElse(""));
if (!node.getPassword().isPresent()) {
builder.env(ENV_KEY_MYSQL_ALLOW_EMPTY_PASSWORD, "true");
}
}
handleDefault(node, new String[] {});
List<Optional<Operation>> lifecycles = new ArrayList<>();
lifecycles.add(node.getStandardLifecycle().getConfigure());
lifecycles.add(node.getStandardLifecycle().getCreate());
if (lifecycles.stream().anyMatch(Optional::isPresent)) {
builder.workdir("/docker-entrypoint-initdb.d");
lifecycles.forEach(e -> {
if (e.isPresent()) {
Operation operation = e.get();
Optional<Artifact> artifact = operation.getArtifact();
if (artifact.isPresent()) {
String path = artifact.get().getFilePath();
if (path.endsWith(".sql")) {
String filename = determineFilename(path);
try {
builder.copyFromCsar(path, "", filename);
} catch (IOException ex) {
logger.error("Copying dependencies of node {} has failed!", node.getEntityName(), ex);
throw new TransformationFailureException("Copying dependencies failed", ex);
}
}
}
}
});
builder.workdir(TOSCANA_ROOT_WORKDIR_PATH);
}
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class GraphNormalizerTest method operationNormalization.
@Test
public void operationNormalization() {
ServiceGraph graph = new ServiceGraph(OPERATION, logMock());
EntityId lifecycleId = ToscaStructure.NODE_TEMPLATES.descend("test-node").descend(RootNode.INTERFACES.name).descend(RootNode.STANDARD_LIFECYCLE.name);
EntityId createId = lifecycleId.descend(StandardLifecycle.CREATE.name);
Entity createEntity = graph.getEntity(createId).get();
Operation create = new TypeWrapper().wrapEntity((MappingEntity) createEntity, Operation.class);
assertTrue(create.getArtifact().isPresent());
Artifact createArtifact = create.getArtifact().get();
assertEquals("test-artifact", createArtifact.getFilePath());
EntityId startId = lifecycleId.descend(StandardLifecycle.START.name);
Entity startEntity = graph.getEntity(startId).get();
Operation start = new TypeWrapper().wrapEntity((MappingEntity) startEntity, Operation.class);
assertTrue(start.getArtifact().isPresent());
Artifact startArtifact = start.getArtifact().get();
assertEquals("test-artifact2", startArtifact.getFilePath());
}
use of org.opentosca.toscana.model.artifact.Artifact in project TOSCAna by StuPro-TOSCAna.
the class LinkResolverTest method resolveRepositoryLink.
@Test
public void resolveRepositoryLink() {
EffectiveModel model = new EffectiveModelFactory().create(REPOSITORY, logMock());
WebServer node = (WebServer) model.getNodeMap().get("test-node");
Set<Artifact> artifacts = node.getArtifacts();
Artifact artifact = artifacts.iterator().next();
assertNotNull(artifact);
Optional<Repository> repo = artifact.getRepository();
assertTrue(repo.isPresent());
assertEquals("http://test.repo.com/", repo.get().getUrl());
}
Aggregations