use of org.alien4cloud.alm.service.exceptions.IncompatibleHalfRelationshipException in project alien4cloud by alien4cloud.
the class ServiceResourceService method validateRelationshipTypes.
private void validateRelationshipTypes(ServiceResource serviceResource, final NodeType nodeType) {
safe(serviceResource.getCapabilitiesRelationshipTypes()).forEach((capabilityName, relationshipTypeId) -> {
RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId);
String[] validTargets = relationshipType.getValidTargets();
if (ArrayUtils.isNotEmpty(validTargets)) {
CapabilityDefinition capabilityDefinition = nodeType.getCapabilities().stream().filter(c -> c.getId().equals(capabilityName)).findFirst().get();
Csar csar = toscaTypeSearchService.getArchive(nodeType.getArchiveName(), nodeType.getArchiveVersion());
Set<CSARDependency> allDependencies = new HashSet<>(safe(csar.getDependencies()));
allDependencies.add(new CSARDependency(csar.getName(), csar.getVersion(), csar.getHash()));
CapabilityType capabilityType = toscaTypeSearchService.getElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), allDependencies);
Set<String> allAcceptedTypes = new HashSet<>();
allAcceptedTypes.addAll(capabilityType.getDerivedFrom());
allAcceptedTypes.add(capabilityType.getElementId());
boolean isValid = false;
for (String validTarget : validTargets) {
if (allAcceptedTypes.contains(validTarget)) {
isValid = true;
break;
}
}
if (!isValid) {
throw new IncompatibleHalfRelationshipException("[" + relationshipType.getId() + "] is not compatible with [" + capabilityType.getId() + "]");
}
}
});
safe(serviceResource.getRequirementsRelationshipTypes()).forEach((k, v) -> {
toscaTypeSearchService.findByIdOrFail(RelationshipType.class, v);
});
}
Aggregations