use of org.opentosca.toscana.model.datatype.Port in project TOSCAna by StuPro-TOSCAna.
the class DockerfileBuildingVisitor method visit.
@Override
public void visit(WebApplication node) {
// If a Web Application does not define a port. add the defaults for HTTP and HTTPS
if (!node.getAppEndpoint().getPort().isPresent()) {
ports.add(80);
ports.add(443);
// Set the ports in the model
node.getAppEndpoint().setPort(new Port(80));
}
handleDefault(node, new String[] {});
}
use of org.opentosca.toscana.model.datatype.Port 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());
}
use of org.opentosca.toscana.model.datatype.Port in project TOSCAna by StuPro-TOSCAna.
the class PrepareModelNodeVisitor method visit.
@Override
public void visit(MysqlDatabase node) {
// if certain values aren't given, fill them
if (node.getPassword().isPresent()) {
// password needs to be at least 8 characters long
String password = node.getPassword().get();
if (password.length() < minPWLength) {
logger.warn("Database password too short, creating new random password");
node.setPassword(randomString(minPWLength));
}
} else {
logger.warn("No database password given, creating new random password");
node.setPassword(randomString(minPWLength));
}
if (!node.getUser().isPresent()) {
logger.warn("User not set, setting to default");
node.setUser(DEFAULT_DB_USER);
}
if (!node.getPort().isPresent()) {
logger.warn("Database port not set, setting to default");
node.setPort(DEFAULT_DB_PORT);
}
// check if Mysql is the only node hosted on his compute node
Compute compute = getCompute(node);
if (topology.incomingEdgesOf(compute).stream().filter(relation -> relation instanceof HostedOn).collect(Collectors.toSet()).size() == 1) {
// means our dbms is the only one hosted on this compute
// means we can set the private address as reference the database endpoint
Fn databaseEndpointFn = Fn.fnGetAtt(toAlphanumerical(node.getEntityName()), AWS_ENDPOINT_REFERENCE);
String databaseEndpoint = databaseEndpointFn.toString(true);
cfnModule.putFn(databaseEndpoint, databaseEndpointFn);
compute.setPrivateAddress(databaseEndpoint);
compute.setPublicAddress(databaseEndpoint);
logger.debug("Set private address and public address of '{}' to reference MysqlDatabase '{}'", compute.getEntityName(), node.getEntityName());
// also the underlying compute should not get mapped to an ec2
cfnModule.removeComputeToEc2(compute);
logger.debug("Removing Compute '{}' to be transformed", compute.getEntityName());
}
}
use of org.opentosca.toscana.model.datatype.Port in project TOSCAna by StuPro-TOSCAna.
the class ScalarTypeConverter method convertScalarEntity.
/**
* Converts the value attached to given {@code scalarEntity } to an instance of a type which is specified by given {@code key}.
*/
static <T> T convertScalarEntity(ScalarEntity scalarEntity, ToscaKey<T> key, Entity parent) {
String value = scalarEntity.getValue();
Class targetType = key.getType();
if (String.class.isAssignableFrom(targetType)) {
return (T) value;
} else if (Integer.class.isAssignableFrom(targetType)) {
Integer number;
if (UNBOUNDED.equals(value)) {
number = Integer.MAX_VALUE;
} else {
number = Integer.valueOf(value);
}
return (T) number;
} else if (Boolean.class.isAssignableFrom(targetType)) {
return (T) Boolean.valueOf(value);
} else if (targetType.isEnum()) {
Map<String, T> enumMap = EnumUtils.getEnumMap(targetType);
Optional<T> result = enumMap.entrySet().stream().filter(entry -> value.equalsIgnoreCase(entry.getKey())).map(Map.Entry::getValue).findAny();
return result.orElseThrow(() -> new NoSuchElementException(String.format("No value with name '%s' in enum '%s'", value, targetType.getSimpleName())));
} else if (OperationVariable.class.isAssignableFrom(targetType)) {
Connection c = scalarEntity.getGraph().getEdge(parent, scalarEntity);
String name = null;
OperationVariable var;
if (c != null) {
name = c.getKey();
var = new OperationVariable(scalarEntity, name);
} else {
var = new OperationVariable(scalarEntity);
}
return (T) var;
} else if (SizeUnit.class.isAssignableFrom(targetType)) {
SizeUnit.Unit fromDefaultUnit = (SizeUnit.Unit) key.getDirectives().get(SizeUnit.FROM);
SizeUnit.Unit toUnit = (SizeUnit.Unit) key.getDirectives().get(SizeUnit.TO);
if (fromDefaultUnit == null || toUnit == null) {
throw new IllegalStateException("ToscaKey defining a SizeUnit is illegal: No directive set for source and target units");
}
return (T) SizeUnit.convert(value, fromDefaultUnit, toUnit);
} else if (Port.class.isAssignableFrom(targetType)) {
return (T) new Port(Integer.valueOf(value));
} else {
throw new UnsupportedOperationException(String.format("Cannot convert value of type %s: currently unsupported", targetType.getSimpleName()));
}
}
Aggregations