Search in sources :

Example 1 with CsarStorageService

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;
}
Also used : Csar(org.opentosca.container.core.model.csar.Csar) CsarId(org.opentosca.container.core.model.csar.CsarId) Logger(org.slf4j.Logger) Message(org.apache.camel.Message) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Exchange(org.apache.camel.Exchange) CsarStorageService(org.opentosca.container.core.service.CsarStorageService) TNodeType(org.eclipse.winery.model.tosca.TNodeType) List(java.util.List) TParameter(org.eclipse.winery.model.tosca.TParameter) Map(java.util.Map) QName(javax.xml.namespace.QName) MBHeader(org.opentosca.bus.management.header.MBHeader) Csar(org.opentosca.container.core.model.csar.Csar) Message(org.apache.camel.Message) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) CsarId(org.opentosca.container.core.model.csar.CsarId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TParameter(org.eclipse.winery.model.tosca.TParameter)

Example 2 with CsarStorageService

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ICoreEndpointService(org.opentosca.container.core.service.ICoreEndpointService) WineryConnector(org.opentosca.container.control.winery.WineryConnector) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) PlanType(org.opentosca.container.core.next.model.PlanType) RelationshipTemplateInstanceService(org.opentosca.container.core.next.services.instances.RelationshipTemplateInstanceService) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) PlanInvokerService(org.opentosca.container.api.service.PlanInvokerService) Map(java.util.Map) Path(java.nio.file.Path) Settings(org.opentosca.container.core.common.Settings) CsarId(org.opentosca.container.core.model.csar.CsarId) NodeTemplateInstanceService(org.opentosca.container.core.next.services.instances.NodeTemplateInstanceService) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) UserException(org.opentosca.container.core.common.UserException) OpenTOSCA_DefrostPlanOperation(org.opentosca.container.core.convention.PlanConstants.OpenTOSCA_DefrostPlanOperation) Collection(java.util.Collection) Set(java.util.Set) DEFAULT_LOCAL_REPO_NAME(org.eclipse.winery.common.Constants.DEFAULT_LOCAL_REPO_NAME) OpenTOSCA_FreezePlanOperation(org.opentosca.container.core.convention.PlanConstants.OpenTOSCA_FreezePlanOperation) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) List(java.util.List) TPlan(org.eclipse.winery.model.tosca.TPlan) Endpoint(org.opentosca.container.core.next.model.Endpoint) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) HashMap(java.util.HashMap) GitBasedRepositoryConfiguration(org.eclipse.winery.common.configuration.GitBasedRepositoryConfiguration) ServiceTemplateInstanceState(org.opentosca.container.core.next.model.ServiceTemplateInstanceState) ArrayList(java.util.ArrayList) SystemException(org.opentosca.container.core.common.SystemException) OpenToscaControlService(org.opentosca.container.control.OpenToscaControlService) PlanInstanceService(org.opentosca.container.core.next.services.instances.PlanInstanceService) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) Csar(org.opentosca.container.core.model.csar.Csar) PlanInstance(org.opentosca.container.core.next.model.PlanInstance) Logger(org.slf4j.Logger) PlanInstanceState(org.opentosca.container.core.next.model.PlanInstanceState) Files(java.nio.file.Files) SystemUtils(org.apache.commons.lang3.SystemUtils) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ServiceTemplateInstanceService(org.opentosca.container.core.next.services.instances.ServiceTemplateInstanceService) CsarStorageService(org.opentosca.container.core.service.CsarStorageService) InputStreamReader(java.io.InputStreamReader) ExecutionException(java.util.concurrent.ExecutionException) FileBasedRepositoryConfiguration(org.eclipse.winery.common.configuration.FileBasedRepositoryConfiguration) Paths(java.nio.file.Paths) PlanInstanceOutput(org.opentosca.container.core.next.model.PlanInstanceOutput) PlanGenerationService(org.opentosca.container.control.plan.PlanGenerationService) RepositoryConfigurationObject(org.eclipse.winery.common.configuration.RepositoryConfigurationObject) BufferedReader(java.io.BufferedReader) Git(org.eclipse.jgit.api.Git) Assert(org.junit.Assert) Csar(org.opentosca.container.core.model.csar.Csar) CsarId(org.opentosca.container.core.model.csar.CsarId)

Aggregations

HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1