use of org.opentosca.container.core.service.CsarStorageService in project container by OpenTOSCA.
the class IManagementBusInvocationPluginService method respondViaMocking.
public Exchange respondViaMocking(final Exchange exchange, CsarStorageService storage) {
final long waitTime = System.currentTimeMillis() + 10000;
while (System.currentTimeMillis() > waitTime) {
// busy waiting here...
}
final Message message = exchange.getIn();
final Map<String, String> responseMap = new HashMap<>();
final Object params = message.getBody();
if (params != null && params instanceof HashMap && ((HashMap) params).containsValue("fault")) {
responseMap.put("Fault", "managementBusMockFaultValue");
}
final String csarId = message.getHeader(MBHeader.CSARID.toString(), String.class);
final String nodeTemplateId = message.getHeader(MBHeader.NODETEMPLATEID_STRING.toString(), String.class);
final String interfaceName = message.getHeader(MBHeader.INTERFACENAME_STRING.toString(), String.class);
final String operationName = message.getHeader(MBHeader.OPERATIONNAME_STRING.toString(), String.class);
Csar csar = storage.findById(new CsarId(csarId));
QName nodeTypeId = csar.entryServiceTemplate().getTopologyTemplate().getNodeTemplate(nodeTemplateId).getTypeAsQName();
TNodeType nodeType = csar.nodeTypes().stream().filter(x -> x.getQName().equals(nodeTypeId)).findFirst().get();
if (nodeType.getInterfaces() != null) {
nodeType.getInterfaces().stream().filter(x -> x.getName().equals(interfaceName)).findFirst().ifPresent(x -> {
List<TParameter> outputParameters = x.getOperations().stream().filter(op -> op.getName().equals(operationName)).findFirst().get().getOutputParameters();
if (outputParameters != null) {
outputParameters.forEach(param -> responseMap.put(param.getName(), "managementBusMockValue"));
}
});
}
LOG.info("Returning following response:");
LOG.info(responseMap.toString());
exchange.getIn().setBody(responseMap);
return exchange;
}
use of org.opentosca.container.core.service.CsarStorageService in project container by OpenTOSCA.
the class TestUtils method storeCsarFileIntoStorage.
public Csar storeCsarFileIntoStorage(QName serviceTemplateId, CsarStorageService storage, Path csarFilePath) throws SystemException, UserException {
CsarId csarId = new CsarId(serviceTemplateId.getLocalPart() + ".csar");
Set<Csar> csars = storage.findAll();
Collection<CsarId> csarIds = csars.stream().map(Csar::id).filter(id -> id.equals(csarId)).collect(Collectors.toList());
if (!csarIds.contains(csarId)) {
storage.storeCSAR(csarFilePath);
}
return storage.findById(csarId);
}
Aggregations