Search in sources :

Example 1 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project yorc-a4c-plugin by ystia.

the class ToscaExportersTest method testComponentSerialization.

@Test
public void testComponentSerialization() throws Exception {
    Mockito.reset(repositorySearchService);
    String rootDir = "src/test/resources/org/ystia/yorc/alien4cloud/plugin/tosca";
    Csar csar = new Csar("tosca-normative-types", "1.0.0-ALIEN20");
    Mockito.when(repositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
    NodeType mockedResult = Mockito.mock(NodeType.class);
    Mockito.when(mockedResult.getArchiveName()).thenReturn("tosca-normative-types");
    Mockito.when(mockedResult.getArchiveVersion()).thenReturn("1.0.0-ALIEN20");
    DeploymentArtifact da = Mockito.mock(DeploymentArtifact.class);
    Mockito.when(da.getArtifactPath()).thenReturn("test");
    Mockito.when(da.getArtifactRef()).thenReturn("test");
    Mockito.when(da.getArtifactType()).thenReturn("file");
    Mockito.when(da.getArchiveName()).thenReturn("tosca-normative-types");
    Mockito.when(da.getArchiveVersion()).thenReturn("1.0.0-ALIEN20");
    Mockito.when(mockedResult.getArtifacts()).thenReturn(Collections.singletonMap("SoftwareComponentArtifact", da));
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(DataType.class), Mockito.eq(NormativeCredentialConstant.DATA_TYPE), Mockito.any(Set.class))).thenReturn(Mockito.mock(DataType.class));
    RelationshipType hostedOn = new RelationshipType();
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(rootDir, "tosca_component_input.yaml"));
    System.out.println(parsingResult.getContext().getParsingErrors());
    assertNoBlocker(parsingResult);
    String resultYaml = toscaComponentExporter.getYaml(parsingResult.getResult());
    System.out.println(resultYaml);
    String expectedResult = FileUtils.readFileToString(Paths.get(rootDir, "tosca_component_output.yaml").toFile(), "UTF-8");
    // Make some whitespaces change here as IDEs have auto-format features that will overwrite them in the file
    expectedResult = expectedResult.replaceAll("verbose:\\n", "verbose: \n");
    expectedResult = expectedResult.replaceAll("default:\\n", "default: \n");
    Assert.assertEquals(expectedResult, resultYaml);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) DataType(org.alien4cloud.tosca.model.types.DataType) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Test(org.junit.Test) AbstractPluginTest(org.ystia.yorc.alien4cloud.plugin.AbstractPluginTest)

Example 2 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project yorc-a4c-plugin by ystia.

the class YorcPaaSProvider method switchMaintenanceMode.

/**
 * Switch the maintenance mode for this deployed topology.
 *
 * @param  ctx the deployment context
 * @param  maintenanceModeOn
 * @throws MaintenanceModeException
 */
@Override
public void switchMaintenanceMode(PaaSDeploymentContext ctx, boolean maintenanceModeOn) throws MaintenanceModeException {
    String paasId = ctx.getDeploymentPaaSId();
    YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
    log.debug(paasId + " switchMaintenanceMode");
    if (jrdi == null) {
        log.error(paasId + " switchMaintenanceMode: No Deployment Information");
        throw new MaintenanceModeException("No Deployment Information");
    }
    Topology topology = jrdi.getDeploymentContext().getDeploymentTopology();
    Map<String, Map<String, InstanceInformation>> nodes = jrdi.getInstanceInformations();
    if (nodes == null || nodes.isEmpty()) {
        log.error(paasId + " switchMaintenanceMode: No Node found");
        throw new MaintenanceModeException("No Node found");
    }
    for (Entry<String, Map<String, InstanceInformation>> nodeEntry : nodes.entrySet()) {
        String node = nodeEntry.getKey();
        Map<String, InstanceInformation> nodeInstances = nodeEntry.getValue();
        if (nodeInstances != null && !nodeInstances.isEmpty()) {
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(node);
            NodeType nodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
        // ALIEN 2.0.0 Update
        /*
                if (isFromType(NormativeComputeConstants.COMPUTE_TYPE, nodeType)) {
                    for (Entry<String, InstanceInformation> nodeInstanceEntry : nodeInstances.entrySet()) {
                        String instance = nodeInstanceEntry.getKey();
                        InstanceInformation iinfo = nodeInstanceEntry.getValue();
                        if (iinfo != null) {
                            doSwitchInstanceMaintenanceMode(paasId, node, instance, iinfo, maintenanceModeOn);
                        }
                    }
                }*/
        }
    }
}
Also used : MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map)

Example 3 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method saveToscaComponentTest.

@Test
public void saveToscaComponentTest() throws IndexingServiceException, IOException {
    dao.save(indexedNodeTypeTest);
    String typeName1 = indexedNodeTypeTest.getClass().getSimpleName().toLowerCase();
    assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName1, indexedNodeTypeTest.getId(), true);
    GetResponse resp = getDocument(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName1, indexedNodeTypeTest.getId());
    log.info(resp.getSourceAsString());
    NodeType nt = jsonMapper.readValue(resp.getSourceAsString(), NodeType.class);
    assertBeanEqualsToOriginal(nt);
    refresh();
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.Test)

Example 4 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method findByIdTest.

@Test
public void findByIdTest() throws IndexingServiceException, JsonProcessingException {
    saveDataToES(indexedNodeTypeTest);
    NodeType nt = dao.findById(NodeType.class, indexedNodeTypeTest.getId());
    assertBeanEqualsToOriginal(nt);
    nt = dao.findById(NodeType.class, indexedNodeTypeTest.getId());
    assertBeanEqualsToOriginal(nt);
    nt = dao.findById(NodeType.class, "5");
    isNull(nt);
    // findByIds
    List<NodeType> lnt = dao.findByIds(NodeType.class, new String[] { indexedNodeTypeTest.getId() });
    List<NodeType> lnt2 = dao.findByIds(NodeType.class, new String[] { indexedNodeTypeTest.getId(), "5" });
    isTrue(!lnt.isEmpty());
    isTrue(!lnt2.isEmpty());
    assertEquals(1, lnt.size());
    assertEquals(1, lnt2.size());
    nt = lnt.get(0);
    assertBeanEqualsToOriginal(nt);
    nt = lnt2.get(0);
    assertBeanEqualsToOriginal(nt);
    // findByIdsWithContext
    saveApplications();
    List<Application> apps = dao.findByIdsWithContext(Application.class, FetchContext.SUMMARY, new String[] { "1", "2", "8" });
    log.info("Search: " + JsonUtil.toString(apps));
    assertNotNull(apps);
    assertFalse(apps.isEmpty());
    assertEquals(2, apps.size());
    String[] expectedId = new String[] { "1", "2" };
    String[] ids = null;
    String[] expectedNames = new String[] { "app1", "app2" };
    String[] names = null;
    for (Application application : apps) {
        ids = ArrayUtils.add(ids, application.getId());
        names = ArrayUtils.add(names, application.getName());
        assertNull(application.getDescription());
    }
    Arrays.sort(expectedId);
    Arrays.sort(ids);
    Arrays.sort(expectedNames);
    Arrays.sort(names);
    assertArrayEquals(expectedId, ids);
    assertArrayEquals(expectedNames, names);
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Application(alien4cloud.model.application.Application) Test(org.junit.Test)

Example 5 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class EsDaoPaginatedSearchTest method testSimpleSearchWellPaginated.

private void testSimpleSearchWellPaginated(int maxElement, int size, Map<String, String[]> filters) throws IOException {
    List<NodeType> expectedDataList = filters != null && filterContainsValue(filters, "jndi") ? new ArrayList<>(jndiTestDataList) : new ArrayList<>(testDataList);
    GetMultipleDataResult<NodeType> searchResp;
    int expectedSize;
    for (int from = 0; from < maxElement; from += size) {
        expectedSize = (maxElement - from) > size ? size : maxElement - from;
        searchResp = dao.find(NodeType.class, filters, from, size);
        assertNotNull(searchResp);
        assertNotNull(searchResp.getTypes());
        assertNotNull(searchResp.getData());
        assertEquals(expectedSize, searchResp.getTypes().length);
        assertEquals(expectedSize, searchResp.getData().length);
        // testing the pertinence of returned data
        Object[] data = searchResp.getData();
        for (Object element : data) {
            NodeType nt = jsonMapper.readValue(jsonMapper.writeValueAsString(element), NodeType.class);
            assertTrue(expectedDataList.contains(nt));
            expectedDataList.remove(nt);
        }
    }
    // assert the list is empty at the end.
    assertTrue(expectedDataList.isEmpty());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7