1 package org.openecomp.sdc.asdctool.migration.tasks.mig1710;
3 import com.google.common.collect.Lists;
5 import org.apache.commons.collections.CollectionUtils;
6 import org.apache.commons.collections.MapUtils;
7 import org.apache.commons.lang3.StringUtils;
8 import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
9 import org.openecomp.sdc.asdctool.migration.core.task.PostMigration;
10 import org.openecomp.sdc.asdctool.migration.tasks.handlers.XlsOutputHandler;
11 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
12 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
13 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
14 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
15 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
16 import org.openecomp.sdc.be.config.ConfigurationManager;
17 import org.openecomp.sdc.be.dao.api.ActionStatus;
18 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
19 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
20 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
21 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
22 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
23 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
24 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
25 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
26 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
27 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
28 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
29 import org.openecomp.sdc.be.impl.ComponentsUtils;
30 import org.openecomp.sdc.be.model.ComponentInstance;
31 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
32 import org.openecomp.sdc.be.model.ComponentParametersView;
33 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
34 import org.openecomp.sdc.be.model.LifecycleStateEnum;
35 import org.openecomp.sdc.be.model.Resource;
36 import org.openecomp.sdc.be.model.User;
37 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
38 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
39 import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
40 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
41 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
42 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
43 import org.openecomp.sdc.exception.ResponseFormat;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.stereotype.Component;
49 import java.util.ArrayList;
50 import java.util.EnumMap;
51 import java.util.HashMap;
52 import java.util.List;
54 import java.util.Optional;
55 import java.util.function.Predicate;
56 import java.util.stream.Collectors;
59 public class UpgradeMigration1710 implements PostMigration {
61 private static final String SERVICE_UUID_RPOPERTY = "providing_service_uuid";
63 private static final String SERVICE_INVARIANT_UUID_RPOPERTY = "providing_service_invariant_uuid";
65 private static final String UNKNOWN = "UNKNOWN";
67 private static final String CHECKOUT_MESSAGE = "checkout upon upgrade migration";
69 private static final String FAILED_TO_CHANGE_STATE_OF_COMPONENT = "Failed to change state of component with name {}, invariantUUID {}, version {} to {}. ";
71 private static final String FAILED_TO_UPGRADE_COMPONENT = "Failed to upgrade {} with name {}, invariantUUID {}, version {}. Operation {}. The reason for failure: {}. ";
73 private static final String UPGRADE_COMPONENT_SUCCEEDED = "Upgrade of {} with name {}, invariantUUID {}, version {} finished successfully. ";
75 private static final String UPGRADE_VFS_FAILED = "Upgrade VFs upon upgrade migration 1710 process failed. ";
77 private static final Logger LOGGER = LoggerFactory.getLogger(UpgradeMigration1710.class);
80 private TitanDao titanDao;
83 private ToscaOperationFacade toscaOperationFacade;
86 private LifecycleBusinessLogic lifecycleBusinessLogic;
89 private IUserAdminOperation userAdminOperation;
92 private ResourceBusinessLogic resourceBusinessLogic;
95 private CsarOperation csarOperation;
98 private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
101 private ComponentsUtils componentsUtils;
103 private XlsOutputHandler outputHandler = new XlsOutputHandler("COMPONENT TYPE", "COMPONENT NAME", "COMPONENT UUID", "COMPONENT UNIQUE_ID", "UPGRADE STATUS", "DESCRIPTION");
105 private User user = null;
107 private final LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction(CHECKOUT_MESSAGE, LifecycleChanceActionEnum.UPGRADE_MIGRATION);
109 private final Map<String, GraphVertex> latestGenericTypes = new HashMap<>();
111 private final Map<String, String> latestOriginResourceVersions = new HashMap<>();
113 private final List<String> proxyServiceContainers = new ArrayList<>();
115 private final List<String> vfAllottedResources = new ArrayList<>();
117 private final List<String> allottedVfContainers = new ArrayList<>();
119 private boolean isVfcUpgradeRequired = false;
121 private boolean skipIfUpgradeVfFailed = true;
123 /***********************************************/
126 public String description() {
127 return "Upgrade migration 1710 - post migration task, which is dedicated to upgrade all latest certified (and not checked out) Node types, VFs and Services. ";
130 private enum UpgradeStatus {
136 public MigrationResult migrate() {
137 LOGGER.info("Starting upgrade migration 1710 process. ");
138 MigrationResult migrationResult = new MigrationResult();
140 boolean result = true;
142 isVfcUpgradeRequired = !ConfigurationManager.getConfigurationManager().getConfiguration().getSkipUpgradeVSPsFlag();
143 skipIfUpgradeVfFailed = ConfigurationManager.getConfigurationManager().getConfiguration().getSkipUpgradeFailedVfs();
144 final String userId = ConfigurationManager.getConfigurationManager().getConfiguration().getAutoHealingOwner();
146 Either<User, ActionStatus> userReq = userAdminOperation.getUserData(userId, false);
147 if (userReq.isRight()) {
149 LOGGER.error("Upgrade migration failed. User {} resolve failed: {} ", userId, userReq.right().value());
151 user = userReq.left().value();
152 LOGGER.info("User {} will perform upgrade operation", user.getUserId());
155 result = upgradeNodeTypes();
158 result = upgradeVFs();
164 upgradeProxyServiceContainers();
167 upgradeAllottedVFs();
170 upgradeAllottedVfContainers();
172 } catch (Exception e) {
174 LOGGER.error("Error occurred {}. ", e);
177 LOGGER.info("Upgrade migration 1710 has been successfully finished. ");
179 migrationResult.setMigrationStatus(MigrationResult.MigrationStatus.COMPLETED);
181 LOGGER.info("Upgrade migration 1710 was failed. ");
183 migrationResult.setMigrationStatus(MigrationResult.MigrationStatus.FAILED);
185 outputHandler.writeOutput();
187 return migrationResult;
190 private void upgradeAllottedVfContainers() {
191 LOGGER.info("Starting upgrade proxy {} service containers upon upgrade migration 1710 process. ", allottedVfContainers.size());
192 for(String currUid : allottedVfContainers){
193 upgradeServiceAndCommitIfNeeded(currUid, component -> true);
197 private StorageOperationStatus upgradeServices() {
198 LOGGER.info("Starting upgrade services upon upgrade migration 1710 process. ");
199 Either<List<String>, TitanOperationStatus> getServicesRes = getAllLatestCertifiedComponentUids(VertexTypeEnum.TOPOLOGY_TEMPLATE, ComponentTypeEnum.SERVICE);
200 if (getServicesRes.isRight()) {
201 return StorageOperationStatus.GENERAL_ERROR;
203 for (String currUid : getServicesRes.left().value()) {
204 upgradeServiceAndCommitIfNeeded(currUid, this::shouldUpgrade);
206 return StorageOperationStatus.OK;
209 private void upgradeServiceAndCommitIfNeeded(String currUid, Predicate<org.openecomp.sdc.be.model.Component> shouldUpgrade) {
210 boolean result = true;
212 result = handleService(currUid, shouldUpgrade);
213 } catch (Exception e) {
215 LOGGER.error("Failed to upgrade Service with uniqueId {} due to a reason {}. ", currUid, e);
227 private void upgradeProxyServiceContainers() {
228 LOGGER.info("Starting upgrade proxy service containers upon upgrade migration 1710 process. ");
229 for(String currUid : proxyServiceContainers){
230 upgradeServiceAndCommitIfNeeded(currUid, component -> true);
234 private boolean handleService(String uniqueId, Predicate<org.openecomp.sdc.be.model.Component> shouldUpgrade) {
235 LOGGER.info("Starting upgrade Service with uniqueId {} upon upgrade migration 1710 process. ", uniqueId);
236 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getServiceRes = toscaOperationFacade.getToscaElement(uniqueId);
237 if(getServiceRes.isRight()){
238 LOGGER.error("Failed to upgrade service with uniqueId {} due to {}. ", uniqueId, getServiceRes.right().value());
239 outputHandler.addRecord(ComponentTypeEnum.SERVICE.name(), UNKNOWN, UNKNOWN, uniqueId, MigrationResult.MigrationStatus.FAILED.name(), getServiceRes.right().value());
242 String derivedFromGenericType = getServiceRes.left().value().getDerivedFromGenericType();
243 LOGGER.debug("derivedFromGenericType: {}", derivedFromGenericType );
244 if (derivedFromGenericType == null) {
245 //malformed field value, upgrade required
246 return upgradeService(getServiceRes.left().value());
248 if(!latestGenericTypes.containsKey(derivedFromGenericType)){
249 Either<List<GraphVertex>, TitanOperationStatus> getDerivedRes = findDerivedResources(derivedFromGenericType);
250 if(getDerivedRes.isRight()){
251 LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, getServiceRes.left().value().getComponentType().getValue(), getServiceRes.left().value().getName(), getServiceRes.left().value().getInvariantUUID(), getServiceRes.left().value().getVersion(), "findDerivedResources", getDerivedRes.right().value());
252 outputHandler.addRecord( getServiceRes.left().value().getComponentType().name(),getServiceRes.left().value().getName(), getServiceRes.left().value().getInvariantUUID(), getServiceRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), getDerivedRes.right().value());
255 latestGenericTypes.put(derivedFromGenericType, getDerivedRes.left().value().get(0));
257 if(latestVersionExists(latestGenericTypes.get(derivedFromGenericType), getServiceRes.left().value().getDerivedFromGenericVersion())){
258 return upgradeService(getServiceRes.left().value());
260 if(!collectLatestOriginResourceVersions(getServiceRes.left().value())){
263 if(shouldUpgrade.test(getServiceRes.left().value())){
264 return upgradeService(getServiceRes.left().value());
266 outputHandler.addRecord(getServiceRes.left().value().getComponentType().name(), getServiceRes.left().value().getName(), getServiceRes.left().value().getInvariantUUID(), getServiceRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), UpgradeStatus.NOT_UPGRADED);
270 private boolean collectLatestOriginResourceVersions(org.openecomp.sdc.be.model.Component component) {
271 if (CollectionUtils.isNotEmpty(component.getComponentInstances())) {
272 for (ComponentInstance instance : component.getComponentInstances()) {
273 if (instance.getOriginType() != OriginTypeEnum.ServiceProxy && !latestOriginResourceVersions.containsKey(instance.getToscaComponentName()) && !addComponent(component, instance)) {
281 private boolean addComponent(org.openecomp.sdc.be.model.Component component, ComponentInstance instance) {
282 VertexTypeEnum vertexType = ModelConverter.getVertexType(instance.getOriginType().name());
283 Either<Resource, StorageOperationStatus> getOriginRes = toscaOperationFacade.getLatestCertifiedByToscaResourceName(instance.getToscaComponentName(), vertexType, JsonParseFlagEnum.ParseMetadata);
284 if (getOriginRes.isRight()) {
285 LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion(), "toscaOperationFacade.getLatestCertifiedByToscaResourceName", getOriginRes.right().value());
286 outputHandler.addRecord(component.getComponentType().name(), component.getName(), component.getInvariantUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), getOriginRes.right().value());
289 latestOriginResourceVersions.put(instance.getToscaComponentName(), getOriginRes.left().value().getVersion());
293 private boolean shouldUpgrade(org.openecomp.sdc.be.model.Component component) {
294 boolean shouldUpgrade = false;
295 if(CollectionUtils.isNotEmpty(component.getComponentInstances())){
296 for(ComponentInstance instance : component.getComponentInstances()){
297 if(instance.getOriginType() == OriginTypeEnum.ServiceProxy){
298 LOGGER.info("The service with name {}, invariantUUID {}, version {}, contains Service proxy instance {}, than the service should be upgraded in the end of the upgrading proccess. ", component.getName(), component.getInvariantUUID(), component.getVersion(), instance.getName());
299 proxyServiceContainers.add(component.getUniqueId());
300 shouldUpgrade = false;
303 if(isAllottedResource(instance.getActualComponentUid())){
304 allottedVfContainers.add(component.getUniqueId());
306 if(isGreater(latestOriginResourceVersions.get(instance.getToscaComponentName()), instance.getComponentVersion())){
307 LOGGER.info("The service with name {}, invariantUUID {}, version {}, contains instance {} from outdated version of origin {} {} , than the service should be upgraded. ", component.getName(), component.getInvariantUUID(), component.getVersion(), instance.getName(), instance.getComponentName(), instance.getComponentVersion());
308 shouldUpgrade = true;
312 return shouldUpgrade;
315 private boolean upgradeService(org.openecomp.sdc.be.model.Component service) {
316 String serviceName = service.getName();
317 String serviceUuid = service.getUUID();
318 LOGGER.info("Starting upgrade Service with name {}, invariantUUID {}, version {} upon upgrade migration 1710 process. ", serviceName, service.getInvariantUUID(), service.getVersion());
319 LOGGER.info("Starting to perform check out of service {}. ", serviceName);
320 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(service.getComponentType(), service.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
321 if (checkouRes.isRight()) {
322 LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, service.getComponentType().getValue(), serviceName, service.getInvariantUUID(), service.getVersion(), "lifecycleBusinessLogic.changeComponentState", checkouRes.right().value().getFormattedMessage());
323 outputHandler.addRecord(service.getComponentType().name(), serviceName, serviceUuid, service.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), checkouRes.right().value().getFormattedMessage());
326 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> updateCompositionRes = updateComposition(checkouRes.left().value());
327 if (updateCompositionRes.isRight()) {
328 LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, service.getComponentType().getValue(), serviceName, service.getInvariantUUID(), service.getVersion(), "updateComposition", updateCompositionRes.right().value().getFormattedMessage());
329 outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), updateCompositionRes.right().value().getFormattedMessage());
332 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> certifyRes = performFullCertification(checkouRes.left().value());
333 if (certifyRes.isRight()) {
334 LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, service.getComponentType().getValue(), serviceName, service.getInvariantUUID(), service.getVersion(), "performFullCertification", certifyRes.right().value().getFormattedMessage());
335 outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), certifyRes.right().value().getFormattedMessage());
338 outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), serviceUuid, checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), UpgradeStatus.UPGRADED);
342 private Either<org.openecomp.sdc.be.model.Component, ResponseFormat> updateComposition(org.openecomp.sdc.be.model.Component component) {
343 Either<ComponentInstance, ResponseFormat> upgradeInstanceRes;
344 for (ComponentInstance instance : component.getComponentInstances()) {
345 upgradeInstanceRes = upgradeInstance(component, instance);
346 if (upgradeInstanceRes.isRight()) {
347 LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion(), "upgradeInstance", upgradeInstanceRes.right().value().getFormattedMessage());
348 outputHandler.addRecord(component.getComponentType().name(), component.getName(), component.getUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), upgradeInstanceRes.right().value().getFormattedMessage());
349 return Either.right(upgradeInstanceRes.right().value());
352 return Either.left(component);
355 private Either<ComponentInstance, ResponseFormat> upgradeInstance(org.openecomp.sdc.be.model.Component component, ComponentInstance instance) {
356 LOGGER.info("Starting upgrade {} instance {} upon upgrade migration 1710 process. ", component.getComponentType().getValue(), instance.getName());
357 ComponentInstance newComponentInstance = new ComponentInstance(instance);
358 if (instance.getOriginType() == OriginTypeEnum.ServiceProxy) {
359 return upgradeServiceProxyInstance(component, instance, newComponentInstance);
361 return upgradeResourceInstance(component, instance, newComponentInstance);
364 private Either<ComponentInstance, ResponseFormat> upgradeResourceInstance(org.openecomp.sdc.be.model.Component component, ComponentInstance instance, ComponentInstance newComponentInstance) {
366 LOGGER.info("Starting upgrade {} instance {} upon upgrade migration 1710 process. ", component.getComponentType().getValue(), instance.getName());
367 Either<ComponentInstance, ResponseFormat> upgradeInstanceRes = null;
368 VertexTypeEnum vertexType = ModelConverter.getVertexType(instance.getOriginType().name());
369 Either<Resource, StorageOperationStatus> getOriginRes = toscaOperationFacade.getLatestCertifiedByToscaResourceName(instance.getToscaComponentName(), vertexType, JsonParseFlagEnum.ParseMetadata);
370 if(getOriginRes.isRight()){
371 LOGGER.info("Upgrade of {} instance {} upon upgrade migration 1710 process failed due to a reason {}. ",
372 component.getComponentType().getValue(), instance.getName(), getOriginRes.right().value());
373 upgradeInstanceRes = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getOriginRes.right().value(), instance.getOriginType().getComponentType())));
375 if(upgradeInstanceRes == null){
376 newComponentInstance.setComponentName(getOriginRes.left().value().getName());
377 newComponentInstance.setComponentUid(getOriginRes.left().value().getUniqueId());
378 newComponentInstance.setComponentVersion(getOriginRes.left().value().getVersion());
379 newComponentInstance.setToscaComponentName(((Resource)getOriginRes.left().value()).getToscaResourceName());
380 if(isGreater(getOriginRes.left().value().getVersion(), instance.getComponentVersion())){
381 upgradeInstanceRes = changeAssetVersion(component, instance, newComponentInstance);
383 if((upgradeInstanceRes == null || upgradeInstanceRes.isLeft()) && isAllottedResource(instance.getComponentUid()) && MapUtils.isNotEmpty(component.getComponentInstancesProperties())){
384 ComponentInstance instanceToUpdate = upgradeInstanceRes == null ? instance : upgradeInstanceRes.left().value();
385 upgradeInstanceRes = Either.left(updateServiceUuidProperty(component, instanceToUpdate, component.getComponentInstancesProperties().get(instance.getUniqueId())));
388 //upgrade nodes contained by CVFC
389 if(upgradeInstanceRes == null && isVfcUpgradeRequired && newComponentInstance.getOriginType() == OriginTypeEnum.CVFC &&
390 !upgradeVf(getOriginRes.left().value().getUniqueId(), false)) {
391 upgradeInstanceRes = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
393 if(upgradeInstanceRes == null){
394 upgradeInstanceRes = Either.left(instance);
396 LOGGER.info("Upgrade of {} instance {} upon upgrade migration 1710 process finished successfully. ",
397 component.getComponentType().getValue(), instance.getName());
398 return upgradeInstanceRes;
401 private ComponentInstance updateServiceUuidProperty(org.openecomp.sdc.be.model.Component component, ComponentInstance instance, List<ComponentInstanceProperty> instanceProperties){
402 if(isAllottedResource(instance.getComponentUid()) && instanceProperties != null){
403 Optional<ComponentInstanceProperty> propertyUuid = instanceProperties.stream().filter(p->p.getName().equals(SERVICE_UUID_RPOPERTY)).findFirst();
404 Optional<ComponentInstanceProperty> propertyInvariantUuid = instanceProperties.stream().filter(p->p.getName().equals(SERVICE_INVARIANT_UUID_RPOPERTY)).findFirst();
405 if(propertyUuid.isPresent() && propertyInvariantUuid.isPresent()){
406 String serviceInvariantUUID = propertyInvariantUuid.get().getValue();
407 Either<List<GraphVertex>, TitanOperationStatus> getLatestOriginServiceRes = getLatestCertifiedService(serviceInvariantUUID);
408 if (getLatestOriginServiceRes.isRight()) {
411 propertyUuid.get().setValue((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.UUID));
412 componentInstanceBusinessLogic.createOrUpdatePropertiesValues(component.getComponentType(), component.getUniqueId(), instance.getUniqueId(), Lists.newArrayList(propertyUuid.get()), user.getUserId())
414 .forEach(e -> LOGGER.debug("Failed to update property {} of the instance {} of the component {}. ", SERVICE_UUID_RPOPERTY, instance.getUniqueId(), component.getName()));
420 private boolean isAllottedResource(String uniqueId){
421 ComponentParametersView filters = new ComponentParametersView(true);
422 filters.setIgnoreCategories(false);
423 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getResourceRes = toscaOperationFacade.getToscaElement(uniqueId, filters);
424 if(getResourceRes.isRight()){
427 if(getResourceRes.left().value().getCategories() != null && getResourceRes.left().value().getCategories().get(0)!= null){
428 return "Allotted Resource".equals(getResourceRes.left().value().getCategories().get(0).getName());
433 private boolean isAllottedVf(org.openecomp.sdc.be.model.Component component){
434 if(component.getComponentType() != ComponentTypeEnum.RESOURCE){
437 if(((Resource)component).getResourceType() != ResourceTypeEnum.VF){
440 return isAllottedResource(component.getUniqueId());
443 private Either<ComponentInstance, ResponseFormat> upgradeServiceProxyInstance(org.openecomp.sdc.be.model.Component component, ComponentInstance instance, ComponentInstance newComponentInstance) {
444 Either<List<GraphVertex>, TitanOperationStatus> getLatestOriginServiceRes = getLatestCertifiedService(instance.getSourceModelInvariant());
445 if (getLatestOriginServiceRes.isRight()) {
446 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(getLatestOriginServiceRes.right().value()), instance.getOriginType().getComponentType())));
448 newComponentInstance.setComponentVersion((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.VERSION));
449 newComponentInstance.setSourceModelUid((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.UNIQUE_ID));
450 newComponentInstance.setSourceModelName((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.NAME));
451 newComponentInstance.setSourceModelUuid((String) getLatestOriginServiceRes.left().value().get(0).getJsonMetadataField(JsonPresentationFields.UUID));
452 return changeAssetVersion(component, instance, newComponentInstance);
455 private Either<List<GraphVertex>, TitanOperationStatus> getLatestCertifiedService(String invariantUUID) {
457 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
458 propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
459 propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
460 propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
461 propertiesToMatch.put(GraphPropertyEnum.INVARIANT_UUID, invariantUUID);
462 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
463 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
464 return titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
467 private Either<ComponentInstance, ResponseFormat> changeAssetVersion(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance instance, ComponentInstance newComponentInstance) {
468 return componentInstanceBusinessLogic.changeComponentInstanceVersion(ComponentTypeEnum.SERVICE_PARAM_NAME, containerComponent.getUniqueId(), instance.getUniqueId(), user.getUserId(), newComponentInstance);
471 private boolean upgradeNodeTypes() {
472 LOGGER.info("Starting upgrade node types upon upgrade migration 1710 process. ");
473 String toscaConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel();
474 Map<String, List<String>> resourcesForUpgrade = ConfigurationManager.getConfigurationManager().getConfiguration().getResourcesForUpgrade();
475 Map<String, org.openecomp.sdc.be.model.Component> upgradedNodeTypesMap = new HashMap<>();
476 List<String> nodeTypes;
477 if (resourcesForUpgrade.containsKey(toscaConformanceLevel)) {
478 nodeTypes = resourcesForUpgrade.get(toscaConformanceLevel);
479 if (nodeTypes != null && !nodeTypes.isEmpty()) {
480 Either<List<String>, TitanOperationStatus> getRes = getAllLatestCertifiedComponentUids(VertexTypeEnum.NODE_TYPE, ComponentTypeEnum.RESOURCE);
481 if (getRes.isRight()) {
484 List<String> allNodeTypes = getRes.left().value();
486 for (String toscaResourceName : nodeTypes) {
487 Either<List<GraphVertex>, StorageOperationStatus> status = getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
488 if (status.isRight()) {
489 LOGGER.error("Failed to find node type {} ", toscaResourceName);
492 List<GraphVertex> vList = status.left().value();
493 for (GraphVertex vertex : vList) {
494 StorageOperationStatus updateRes = upgradeNodeType(vertex, upgradedNodeTypesMap, allNodeTypes, nodeTypes);
495 if (updateRes != StorageOperationStatus.OK) {
505 private boolean upgradeVFs() {
506 return upgradeVFs(false);
509 private boolean upgradeAllottedVFs() {
510 LOGGER.info("Starting upgrade {} allotted Vfs with upon upgrade migration 1710 process. ", vfAllottedResources.size());
511 return upgradeVFs(true);
514 private boolean upgradeVFs(boolean allottedVfsUpgrade) {
515 LOGGER.info("Starting upgrade VFs upon upgrade migration 1710 process. ");
516 Either<List<String>, TitanOperationStatus> getVfsRes = getAllLatestCertifiedComponentUids(VertexTypeEnum.TOPOLOGY_TEMPLATE, ComponentTypeEnum.RESOURCE);
517 if (getVfsRes.isRight()) {
518 LOGGER.info(UPGRADE_VFS_FAILED);
521 for (String currUid : getVfsRes.left().value()) {
522 boolean result = true;
524 result = upgradeVf(currUid, allottedVfsUpgrade);
525 if (!result && !skipIfUpgradeVfFailed) {
528 } catch (Exception e) {
529 LOGGER.error("The exception {} occured upon upgrade VFs. ", e);
531 if (!skipIfUpgradeVfFailed) {
537 LOGGER.error("Failed to upgrade RESOURCE with uniqueId {} ", currUid);
541 LOGGER.info("RESOURCE upgrade finished successfully: uniqueId {} ", currUid);
546 LOGGER.info("Upgrade VFs upon upgrade migration 1710 process finished successfully. ");
550 private boolean upgradeVf(String uniqueId, boolean allottedVfsUpgrade) {
551 LOGGER.info("Starting upgrade VF with uniqueId {} upon upgrade migration 1710 process. ", uniqueId);
552 Either<String, StorageOperationStatus> latestVersionRes;
553 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getRes = toscaOperationFacade.getToscaElement(uniqueId);
554 if (getRes.isRight()) {
555 LOGGER.debug("Failed to fetch VF with uniqueId {} upon upgrade migration 1710 process. ", uniqueId);
556 outputHandler.addRecord(ComponentTypeEnum.RESOURCE.name(), UNKNOWN, UNKNOWN, uniqueId, MigrationResult.MigrationStatus.FAILED.name(), getRes.right().value());
559 if(!allottedVfsUpgrade && isAllottedVf(getRes.left().value())){
560 vfAllottedResources.add(uniqueId);
563 if (StringUtils.isNotEmpty(getRes.left().value().getCsarUUID())) {
564 LOGGER.info("Going to fetch the latest version of VSP with csarUUID {} upon upgrade migration 1710 process. ", getRes.left().value().getCsarUUID());
565 latestVersionRes = csarOperation.getCsarLatestVersion(getRes.left().value().getCsarUUID(), user);
566 if (latestVersionRes.isRight()) {
567 LOGGER.debug("Failed to fetch the latest version of VSP with csarUUID {} upon upgrade migration 1710 process. ", getRes.left().value().getCsarUUID());
568 outputHandler.addRecord(getRes.left().value().getComponentType().name(), getRes.left().value().getName(), getRes.left().value().getUUID(), getRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), latestVersionRes.right().value());
571 if (isGreater(latestVersionRes.left().value(), getRes.left().value().getCsarVersion())) {
572 return upgradeVfWithLatestVsp(getRes.left().value(), latestVersionRes);
574 if (!isVfcUpgradeRequired) {
575 LOGGER.warn("Warning: No need to upgrade VF with name {}, invariantUUID {}, version {} and VSP version {}. No new version of VSP. ", getRes.left().value().getName(), getRes.left().value().getInvariantUUID(), getRes.left().value().getVersion(), getRes.left().value().getCsarVersion());
578 return upgradeComponentWithLatestGeneric(getRes.left().value());
581 private boolean upgradeVfWithLatestVsp(org.openecomp.sdc.be.model.Component vf, Either<String, StorageOperationStatus> latestVersionRes) {
582 LOGGER.info("Starting upgrade vf with name {}, invariantUUID {}, version {} and latest VSP version {} upon upgrade migration 1710 process. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
583 LOGGER.info("Starting to perform check out of vf with name {}, invariantUUID {}, version {}. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion());
584 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(vf.getComponentType(), vf.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
585 if (checkouRes.isRight()) {
586 outputHandler.addRecord(vf.getComponentType().name(), vf.getName(), vf.getUUID(), vf.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), checkouRes.right().value().getFormattedMessage());
589 LOGGER.info("Starting update vf with name {}, invariantUUID {}, version {} and latest VSP {}. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
590 Resource resourceToUpdate = new Resource(((Resource) checkouRes.left().value()).getComponentMetadataDefinition());
591 resourceToUpdate.setDerivedFromGenericType(((Resource) checkouRes.left().value()).getDerivedFromGenericType());
592 resourceToUpdate.setDerivedFromGenericVersion(((Resource) checkouRes.left().value()).getDerivedFromGenericVersion());
593 resourceToUpdate.setCsarVersion(Double.toString(Double.parseDouble(latestVersionRes.left().value())));
594 Either<Resource, ResponseFormat> updateResourceFromCsarRes = resourceBusinessLogic.validateAndUpdateResourceFromCsar(resourceToUpdate, user, null, null, resourceToUpdate.getUniqueId());
595 if (updateResourceFromCsarRes.isRight()) {
596 outputHandler.addRecord(resourceToUpdate.getComponentType().name(), resourceToUpdate.getName(), resourceToUpdate.getUUID(), resourceToUpdate.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), updateResourceFromCsarRes.right().value().getFormattedMessage());
597 LOGGER.info("Failed to update vf with name {}, invariantUUID {}, version {} and latest VSP {}. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
600 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> certifyRes = performFullCertification(checkouRes.left().value());
601 if (certifyRes.isRight()) {
602 LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getVersion(), LifeCycleTransitionEnum.CERTIFY);
603 outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), certifyRes.right().value().getFormattedMessage());
606 LOGGER.info("Full certification of vf with name {}, invariantUUID {}, version {} finished . ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersionRes.left().value());
607 outputHandler.addRecord(certifyRes.left().value().getComponentType().name(), certifyRes.left().value().getName(), certifyRes.left().value().getUUID(), certifyRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), UpgradeStatus.UPGRADED);
611 private boolean upgradeComponentWithLatestGeneric(org.openecomp.sdc.be.model.Component component) {
612 String derivedFromGenericType = component.getDerivedFromGenericType();
613 String derivedFromGenericVersion = component.getDerivedFromGenericVersion();
614 org.openecomp.sdc.be.model.Component updatedComponent = component;
615 if (StringUtils.isNotEmpty(derivedFromGenericType) && !latestGenericTypes.containsKey(derivedFromGenericType)) {
616 LOGGER.info("Starting upgrade vf with name {}, invariantUUID {}, version {}, latest derived from generic type {}, latest derived from generic version {}. ", component.getName(), component.getInvariantUUID(), component.getVersion(), derivedFromGenericType, derivedFromGenericVersion);
617 LOGGER.info("Starting to fetch latest generic node type {}. ", derivedFromGenericType);
618 Either<List<GraphVertex>, TitanOperationStatus> getDerivedRes = findDerivedResources(derivedFromGenericType);
619 if (getDerivedRes.isRight()) {
620 outputHandler.addRecord(component.getComponentType().name(), component.getName(), component.getInvariantUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), getDerivedRes.right().value());
621 LOGGER.info("Failed to upgrade component with name {}, invariantUUID {}, version {} and latest generic. Status is {}. ", component.getName(), component.getInvariantUUID(), component.getVersion(), derivedFromGenericType);
624 latestGenericTypes.put(derivedFromGenericType, getDerivedRes.left().value().get(0));
626 if (StringUtils.isEmpty(derivedFromGenericType) ||
627 latestVersionExists(latestGenericTypes.get(derivedFromGenericType), derivedFromGenericVersion) ||
628 isVfcUpgradeRequired) {
629 if (StringUtils.isNotEmpty(derivedFromGenericType))
630 LOGGER.info("Newer version {} of derived from generic type {} exists. ", latestGenericTypes.get(derivedFromGenericType).getJsonMetadataField(JsonPresentationFields.VERSION), derivedFromGenericType);
632 LOGGER.info("The vf resource with name {}, invariantUUID {}, version {}, has an empty derivedFromGenericType field. ", component.getName(), component.getInvariantUUID(), component.getVersion());
634 LOGGER.info("Starting to perform check out of vf with name {}, invariantUUID {}, version {}. ", component.getName(), component.getInvariantUUID(), component.getVersion());
635 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), component.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
636 if (checkouRes.isRight()) {
637 LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CHECKOUT);
638 outputHandler.addRecord(component.getComponentType().name(), component.getName(), component.getInvariantUUID(), component.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), checkouRes.right().value().getFormattedMessage());
641 //update included VFCs, if it is required as per configuration
642 if (CollectionUtils.isNotEmpty(checkouRes.left().value().getComponentInstances())) {
643 LOGGER.info("VFC upgrade is required: updating components of vf with name {}, invariantUUID {}, version {}. ", component.getName(), component.getInvariantUUID(), component.getVersion());
644 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> updateCompositionRes =
645 updateComposition(checkouRes.left().value());
646 if (updateCompositionRes.isRight()) {
647 LOGGER.error(FAILED_TO_UPGRADE_COMPONENT, checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getVersion(), "updateComposition", updateCompositionRes.right().value().getFormattedMessage());
648 outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), updateCompositionRes.right().value().getFormattedMessage());
652 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> certifyRes = performFullCertification(checkouRes.left().value());
653 if (certifyRes.isRight()) {
654 LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CERTIFY);
655 outputHandler.addRecord(checkouRes.left().value().getComponentType().name(), checkouRes.left().value().getName(), checkouRes.left().value().getInvariantUUID(), checkouRes.left().value().getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), certifyRes.right().value().getFormattedMessage());
658 updatedComponent = certifyRes.left().value();
660 LOGGER.info("The version {} of derived from generic type {} is up to date. No need to upgrade component with name {}, invariantUUID {} and version {}. ", latestGenericTypes.get(derivedFromGenericType), derivedFromGenericType, component.getName(), component.getInvariantUUID(), component.getVersion());
662 LOGGER.info(UPGRADE_COMPONENT_SUCCEEDED, component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion());
663 outputHandler.addRecord(updatedComponent.getComponentType().name(), updatedComponent.getName(), updatedComponent.getUUID(), updatedComponent.getUniqueId(), MigrationResult.MigrationStatus.COMPLETED.name(), updatedComponent.equals(component) ? UpgradeStatus.NOT_UPGRADED : UpgradeStatus.UPGRADED);
667 private StorageOperationStatus upgradeNodeType(GraphVertex nodeTypeV, Map<String, org.openecomp.sdc.be.model.Component> upgradedNodeTypesMap, List<String> allCertifiedUids, List<String> nodeTypes) {
668 StorageOperationStatus result = StorageOperationStatus.OK;
669 LOGGER.info("Starting upgrade node type with name {}, invariantUUID {}, version{}. ", nodeTypeV.getMetadataProperty(GraphPropertyEnum.NAME), nodeTypeV.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID), nodeTypeV.getMetadataProperty(GraphPropertyEnum.VERSION));
670 LOGGER.info("Starting to find derived to for node type with name {}, invariantUUID {}, version{}. ", nodeTypeV.getMetadataProperty(GraphPropertyEnum.NAME), nodeTypeV.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID), nodeTypeV.getMetadataProperty(GraphPropertyEnum.VERSION));
671 Either<List<GraphVertex>, TitanOperationStatus> parentResourceRes = titanDao.getParentVertecies(nodeTypeV, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseMetadata);
672 if (parentResourceRes.isRight() && parentResourceRes.right().value() != TitanOperationStatus.NOT_FOUND) {
673 return DaoStatusConverter.convertTitanStatusToStorageStatus(parentResourceRes.right().value());
676 List<GraphVertex> derivedResourcesUid = new ArrayList<>();
677 if (parentResourceRes.isLeft()) {
678 for (GraphVertex chV : parentResourceRes.left().value()) {
679 Optional<String> op = allCertifiedUids.stream().filter(id -> id.equals((String) chV.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID))).findAny();
680 if (op.isPresent()) {
681 derivedResourcesUid.add(chV);
685 String uniqueId = (String) nodeTypeV.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID);
686 Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getRes = toscaOperationFacade.getToscaElement(uniqueId);
687 if (getRes.isRight()) {
688 LOGGER.info("failed to fetch element with uniqueId {} ", uniqueId);
689 return getRes.right().value();
692 org.openecomp.sdc.be.model.Resource nt = (Resource) getRes.left().value();
693 boolean isNeedToUpgrade = true;
694 if (upgradedNodeTypesMap.containsKey(nt.getToscaResourceName()) || nodeTypes.stream().anyMatch(p -> p.equals(nt.getToscaResourceName()))) {
695 isNeedToUpgrade = false;
697 if (isNeedToUpgrade) {
698 LOGGER.info("Starting to perform check out of node type with name {}, invariantUUID {}, version {}. ", nt.getName(), nt.getInvariantUUID(), nt.getVersion());
699 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> checkouRes = lifecycleBusinessLogic.changeComponentState(nt.getComponentType(), nt.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT, changeInfo, true, false);
700 if (checkouRes.isRight()) {
701 return StorageOperationStatus.GENERAL_ERROR;
703 org.openecomp.sdc.be.model.Component upgradetComp = checkouRes.left().value();
704 boolean res = performFullCertification(upgradetComp).isLeft();
706 return StorageOperationStatus.GENERAL_ERROR;
708 upgradedNodeTypesMap.put(nt.getToscaResourceName(), upgradetComp);
711 for (GraphVertex chV : derivedResourcesUid) {
712 result = upgradeNodeType(chV, upgradedNodeTypesMap, allCertifiedUids, nodeTypes);
713 LOGGER.info("Upgrade node type with name {}, invariantUUID {}, version {} has been finished with the status {}", chV.getMetadataProperty(GraphPropertyEnum.NAME), chV.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID), chV.getMetadataProperty(GraphPropertyEnum.VERSION), result);
718 private Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> performFullCertification(org.openecomp.sdc.be.model.Component component) {
719 LOGGER.info("Starting to perform full certification of {} with name {}, invariantUUID {}, version {}. ",
720 component.getComponentType().getValue(), component.getName(), component.getInvariantUUID(), component.getVersion());
722 Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> changeStateEither = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), component.getUniqueId(), user, LifeCycleTransitionEnum.CERTIFICATION_REQUEST, changeInfo, true, false);
723 if (changeStateEither.isRight()) {
724 LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CERTIFICATION_REQUEST);
725 return changeStateEither;
727 changeStateEither = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), changeStateEither.left().value().getUniqueId(), user, LifeCycleTransitionEnum.START_CERTIFICATION, changeInfo, true, false);
728 if (changeStateEither.isRight()) {
729 LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.START_CERTIFICATION);
730 return changeStateEither;
732 changeStateEither = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), changeStateEither.left().value().getUniqueId(), user, LifeCycleTransitionEnum.CERTIFY, changeInfo, true, false);
733 if (changeStateEither.isRight()) {
734 LOGGER.info(FAILED_TO_CHANGE_STATE_OF_COMPONENT, component.getName(), component.getInvariantUUID(), component.getVersion(), LifeCycleTransitionEnum.CERTIFY);
736 LOGGER.info("Full certification of {} with name {}, invariantUUID {}, version {} finished successfully",
737 changeStateEither.left().value().getComponentType().getValue(), changeStateEither.left().value().getName(),
738 changeStateEither.left().value().getInvariantUUID(), changeStateEither.left().value().getVersion());
740 return changeStateEither;
743 private Either<List<GraphVertex>, TitanOperationStatus> findDerivedResources(String parentResource) {
744 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
745 propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
747 propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, parentResource);
748 propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
750 return titanDao.getByCriteria(VertexTypeEnum.NODE_TYPE, propertiesToMatch, JsonParseFlagEnum.ParseMetadata);
753 private boolean latestVersionExists(GraphVertex latestDerivedFrom, String currentVersion) {
754 return isGreater((String) latestDerivedFrom.getJsonMetadataField(JsonPresentationFields.VERSION), currentVersion);
757 private boolean isGreater(String latestVersion, String currentVersion) {
758 if (latestVersion != null && currentVersion == null)
760 if (latestVersion == null)
762 return Double.parseDouble(latestVersion) > Double.parseDouble(currentVersion);
765 private Either<List<String>, TitanOperationStatus> getAllLatestCertifiedComponentUids(VertexTypeEnum vertexType, ComponentTypeEnum componentType) {
766 LOGGER.info("Starting to fetch all latest certified not checked out components with type {} upon upgrade migration 1710 process", componentType);
767 Either<List<String>, TitanOperationStatus> result = null;
768 Map<String, String> latestCertifiedMap = new HashMap<>();
769 Map<String, String> latestNotCertifiedMap = new HashMap<>();
771 Either<List<GraphVertex>, TitanOperationStatus> getComponentsRes = getAllLatestCertifiedComponents(vertexType, componentType);
772 if (getComponentsRes.isRight() && getComponentsRes.right().value() != TitanOperationStatus.NOT_FOUND) {
773 LOGGER.error("Failed to fetch all latest certified not checked out components with type {}. Status is {}. ", componentType, getComponentsRes.right().value());
774 result = Either.right(getComponentsRes.right().value());
776 if (getComponentsRes.isRight()) {
777 result = Either.left(new ArrayList<>());
779 if (result == null) {
780 for (GraphVertex component : getComponentsRes.left().value()) {
781 String invariantUUID = (String) component.getJsonMetadataField(JsonPresentationFields.INVARIANT_UUID);
782 if (((String) component.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals(LifecycleStateEnum.CERTIFIED.name())) {
783 latestCertifiedMap.put(invariantUUID, (String) component.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID));
785 latestNotCertifiedMap.put(invariantUUID, (String) component.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID));
788 result = Either.left(latestCertifiedMap.entrySet().stream().filter(e -> !latestNotCertifiedMap.containsKey(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList()));
793 private Either<List<GraphVertex>, TitanOperationStatus> getAllLatestCertifiedComponents(VertexTypeEnum vertexType, ComponentTypeEnum componentType) {
795 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
796 propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
797 propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
799 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
800 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
801 if (vertexType == VertexTypeEnum.TOPOLOGY_TEMPLATE && componentType == ComponentTypeEnum.RESOURCE)
802 propertiesNotToMatch.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.CVFC.name());
803 return titanDao.getByCriteria(vertexType, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
806 protected Either<List<String>, TitanOperationStatus> findResourcesPathRecursively(GraphVertex nodeTypeV, List<String> allCertifiedUids) {
807 Either<List<GraphVertex>, TitanOperationStatus> parentResourceRes = titanDao.getParentVertecies(nodeTypeV, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseMetadata);
808 if (parentResourceRes.isRight()) {
809 return Either.right(parentResourceRes.right().value());
811 List<GraphVertex> derivedResourcesUid = new ArrayList<>();
812 for (GraphVertex chV : parentResourceRes.left().value()) {
813 Optional<String> op = allCertifiedUids.stream().filter(id -> id.equals((String) chV.getJsonMetadataField(JsonPresentationFields.UNIQUE_ID))).findAny();
814 if (op.isPresent()) {
815 derivedResourcesUid.add(chV);
821 private Either<List<GraphVertex>, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName) {
823 Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
824 Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
826 propertiesToMatch.put(property, nodeName);
827 propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
829 Either<List<GraphVertex>, TitanOperationStatus> highestResources = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata);
830 if (highestResources.isRight()) {
831 TitanOperationStatus status = highestResources.right().value();
832 LOGGER.debug("Failed to fetch resource with name {}. Status is {} ", nodeName, status);
833 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
835 List<GraphVertex> resources = highestResources.left().value();
836 List<GraphVertex> result = new ArrayList<>();
837 for (GraphVertex component : resources) {
838 if (((String) component.getJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE)).equals(LifecycleStateEnum.CERTIFIED.name())) {
839 result.add(component);
842 return Either.left(result);