summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ArtifactsOperations.java
blob: a3cb41f1c08010011164643d011fbcfbe52ee4c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
package org.openecomp.sdc.be.model.jsontitan.operations;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import fj.data.Either;

@org.springframework.stereotype.Component("artifacts-operations")

public class ArtifactsOperations extends BaseOperation {
	private static Logger log = LoggerFactory.getLogger(ArtifactsOperations.class.getName());

	public Either<ArtifactDefinition, StorageOperationStatus> addArifactToComponent(ArtifactDefinition artifactInfo, String parentId, NodeTypeEnum type, boolean failIfExist, String instanceId) {

		Either<ArtifactDataDefinition, StorageOperationStatus> status = updateArtifactOnGraph(parentId, artifactInfo, type, artifactInfo.getUniqueId(), instanceId, false);
		if (status.isRight()) {

			log.debug("Failed to update artifact {} of {} {}. status is {}", artifactInfo.getArtifactName(), type.getName(), parentId, status.right().value());
			BeEcompErrorManager.getInstance().logBeFailedUpdateNodeError("Update Artifact", artifactInfo.getArtifactName(), String.valueOf(status.right().value()));
			return Either.right(status.right().value());
		} else {

			ArtifactDataDefinition artifactData = status.left().value();

			ArtifactDefinition artifactDefResult = convertArtifactDataToArtifactDefinition(artifactInfo, artifactData);
			log.debug("The returned ArtifactDefintion is {}", artifactDefResult);
			return Either.left(artifactDefResult);
		}

	}

	public Either<ArtifactDefinition, StorageOperationStatus> updateArifactOnResource(ArtifactDefinition artifactInfo, String id, String artifactId, NodeTypeEnum type, String instanceId) {

		Either<ArtifactDataDefinition, StorageOperationStatus> status = updateArtifactOnGraph(id, artifactInfo, type, artifactId, instanceId, true);
		if (status.isRight()) {

			log.debug("Failed to update artifact {} of {} {}. status is {}", artifactInfo.getArtifactName(), type.getName(), id, status.right().value());
			BeEcompErrorManager.getInstance().logBeFailedUpdateNodeError("Update Artifact", artifactInfo.getArtifactName(), String.valueOf(status.right().value()));
			return Either.right(status.right().value());
		} else {

			ArtifactDataDefinition artifactData = status.left().value();

			ArtifactDefinition artifactDefResult = convertArtifactDataToArtifactDefinition(artifactInfo, artifactData);
			log.debug("The returned ArtifactDefintion is {}", artifactDefResult);
			return Either.left(artifactDefResult);
		}
	}

	public Either<Boolean, StorageOperationStatus> isCloneNeeded(String parentId, ArtifactDefinition artifactInfo, NodeTypeEnum type) {
		ArtifactGroupTypeEnum groupType = artifactInfo.getArtifactGroupType();

		Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> triple = getEdgeLabelEnumFromArtifactGroupType(groupType, type);
		EdgeLabelEnum edgeLabelEnum = triple.getLeft();
		return super.isCloneNeeded(parentId, edgeLabelEnum);
	}

	public Either<ArtifactDefinition, StorageOperationStatus> getArtifactById(String parentId, String id) {
		return getArtifactById(parentId, id, null, null);
	}

	public Either<ArtifactDefinition, StorageOperationStatus> getArtifactById(String parentId, String id, ComponentTypeEnum componentType, String containerId) {
		Either<ArtifactDefinition, StorageOperationStatus> result = null;
		ArtifactDataDefinition foundArtifact = null;
		if (componentType != null && componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
			foundArtifact = getInstanceArtifactByLabelAndId(parentId, id, containerId, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
			if ( foundArtifact == null ){
				foundArtifact = getInstanceArtifactByLabelAndId(parentId, id, containerId, EdgeLabelEnum.INSTANCE_ARTIFACTS);
			}
		}
		if (foundArtifact == null) {
			foundArtifact = getArtifactByLabelAndId(parentId, id, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
		}
		if (foundArtifact == null) {
			foundArtifact = getArtifactByLabelAndId(parentId, id, EdgeLabelEnum.TOSCA_ARTIFACTS);
		}

		if (foundArtifact == null) {
			foundArtifact = getArtifactByLabelAndId(parentId, id, EdgeLabelEnum.ARTIFACTS);
		}

		if (foundArtifact == null) {
			foundArtifact = getArtifactByLabelAndId(parentId, id, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
		}

		if (foundArtifact == null) {
			result = Either.right(StorageOperationStatus.NOT_FOUND);
			return result;
		}

		ArtifactDefinition artifactDefResult = convertArtifactDataToArtifactDefinition(null, foundArtifact);
		return Either.left(artifactDefResult);

	}

	public Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromResource(String id, String artifactId, NodeTypeEnum type, boolean deleteMandatoryArtifact) {
		Either<ArtifactDefinition, StorageOperationStatus> status = removeArtifactOnGraph(id, artifactId, type, deleteMandatoryArtifact);

		if (status.isRight()) {

			log.debug("Failed to delete artifact {} of resource {}", artifactId, id);

			BeEcompErrorManager.getInstance().logBeFailedDeleteNodeError("Delete Artifact", artifactId, String.valueOf(status.right().value()));
			return Either.right(status.right().value());
		} else {

			return Either.left(status.left().value());
		}
	}

	public Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifacts(String parentId, NodeTypeEnum parentType, ArtifactGroupTypeEnum groupType, String instanceId) {

		Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> triple = getEdgeLabelEnumFromArtifactGroupType(groupType, parentType);
		EdgeLabelEnum edgeLabelEnum = triple.getLeft();

		Either<Map<String, ArtifactDefinition>, TitanOperationStatus> foundArtifact = null;
		Map<String, ArtifactDefinition> resMap = new HashMap<>();
		foundArtifact = getArtifactByLabel(parentId, instanceId, edgeLabelEnum);
		if (foundArtifact.isRight()) {
			log.debug("Failed to find artifact in component {} with label {} ", parentId, edgeLabelEnum);
			return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(foundArtifact.right().value()));
		}

		resMap.putAll(foundArtifact.left().value());

		return Either.left(resMap);
	}

	public Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifacts(String parentId) {

		Either<Map<String, ArtifactDefinition>, TitanOperationStatus> foundArtifact = null;
		Map<String, ArtifactDefinition> resMap = new HashMap<>();
		foundArtifact = getArtifactByLabel(parentId, null, EdgeLabelEnum.ARTIFACTS);
		if (foundArtifact.isLeft()) {
			resMap.putAll(foundArtifact.left().value());

		}
		foundArtifact = getArtifactByLabel(parentId, null, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
		if (foundArtifact.isLeft()) {
			resMap.putAll(foundArtifact.left().value());

		}
		foundArtifact = getArtifactByLabel(parentId, null, EdgeLabelEnum.TOSCA_ARTIFACTS);
		if (foundArtifact.isLeft()) {
			resMap.putAll(foundArtifact.left().value());

		}

		return Either.left(resMap);

	}

	public Either<ArtifactDefinition, StorageOperationStatus> removeArtifactOnGraph(String id, String artifactId, NodeTypeEnum type, boolean deleteMandatoryArtifact) {

		Either<ArtifactDefinition, StorageOperationStatus> artifactData = this.getArtifactById(id, artifactId);
		if (artifactData.isRight()) {
			log.debug("Failed to find artifact in component {} with id {} ", id, artifactId);
			return Either.right(artifactData.right().value());
		}
		ArtifactDataDefinition artifactDefinition = artifactData.left().value();
		boolean isMandatory = false;
		if ((artifactDefinition.getMandatory() || artifactDefinition.getServiceApi()) && !deleteMandatoryArtifact) {
			// return Either.left(artifactData.left().value());
			isMandatory = true;
		}

		Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> triple = getEdgeLabelEnumFromArtifactGroupType(artifactDefinition.getArtifactGroupType(), type);
		EdgeLabelEnum edgeLabelEnum = triple.getLeft();
		VertexTypeEnum vertexTypeEnum = triple.getRight();

		if (!isMandatory) {
			StorageOperationStatus status = deleteToscaDataElement(id, edgeLabelEnum, vertexTypeEnum, artifactDefinition.getArtifactLabel(), JsonPresentationFields.ARTIFACT_LABEL);
			if (status != StorageOperationStatus.OK)
				return Either.right(status);
		}

		return Either.left(artifactData.left().value());

	}

	public void updateUUID(ArtifactDataDefinition artifactData, String oldChecksum, String oldVesrion, boolean isUpdate) {
		if (oldVesrion == null || oldVesrion.isEmpty())
			oldVesrion = "0";

		String currentChecksum = artifactData.getArtifactChecksum();
		if(isUpdate && artifactData.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType())){
			generateUUID(artifactData, oldVesrion);
		}
		if (oldChecksum == null || oldChecksum.isEmpty()) {
			if (currentChecksum != null) {
				generateUUID(artifactData, oldVesrion);
			}
		} else if ((currentChecksum != null && !currentChecksum.isEmpty()) && !oldChecksum.equals(currentChecksum)) {
			generateUUID(artifactData, oldVesrion);
		}

	}

	// @TODO add implementation

	public Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifacts(String parentId, NodeTypeEnum parentType) {
		return null;
	}

	public Either<ArtifactDefinition, StorageOperationStatus> addHeatEnvArtifact(ArtifactDefinition artifactHeatEnv, ArtifactDefinition artifactHeat, String componentId, NodeTypeEnum parentType, boolean failIfExist, String instanceId) {
		artifactHeatEnv.setGeneratedFromId(artifactHeat.getUniqueId());
		return addArifactToComponent(artifactHeatEnv, componentId, parentType, failIfExist, instanceId);
	}

	public Either<ArtifactDefinition, StorageOperationStatus> getHeatArtifactByHeatEnvId(String parentId, ArtifactDefinition heatEnv, NodeTypeEnum parentType, String containerId, ComponentTypeEnum componentType) {
		String id = heatEnv.getGeneratedFromId();
		ComponentTypeEnum compType;
		switch (parentType) {
		case ResourceInstance:
			compType = ComponentTypeEnum.RESOURCE_INSTANCE;
			break;
		default:
			compType = componentType;
		}
		return getArtifactById(parentId, id, compType, containerId);
	}

	public Either<ArtifactDefinition, StorageOperationStatus> updateHeatEnvArtifact(String id, ArtifactDefinition artifactEnvInfo, String artifactId, String newArtifactId, NodeTypeEnum type, String instanceId) {

		Either<Map<String, ArtifactDefinition>, TitanOperationStatus> artifactsEither = getArtifactByLabel(id, instanceId, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS);
		if (artifactsEither.isRight()) {
			log.debug("Failed to find artifacts in component {} with id {} ", id, artifactsEither.right().value());
			return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(artifactsEither.right().value()));
		}

		Map<String, ArtifactDefinition> artifacts = artifactsEither.left().value();
		List<ArtifactDefinition> envList = artifacts.values().stream().filter(a -> a.getGeneratedFromId()!= null && a.getGeneratedFromId().equals(artifactId)).collect(Collectors.toList());
		if (envList != null && !envList.isEmpty()) {
			envList.forEach(a -> {
				a.setGeneratedFromId(newArtifactId);
				updateArifactOnResource(a, id, a.getUniqueId(), type, instanceId);

			});

		}
		return Either.left(artifactEnvInfo);
	}

	public Either<ArtifactDefinition, StorageOperationStatus> updateHeatEnvPlaceholder(ArtifactDefinition artifactInfo, String parentId, NodeTypeEnum type) {
		return updateArifactOnResource(artifactInfo, parentId, artifactInfo.getUniqueId(), type, null);
	}

	// public Either<List<HeatParameterDefinition>, StorageOperationStatus> getHeatParamsForEnv(ArtifactDefinition heatEnvArtifact, String parentId) {
	// return null;
	// }

	///////////////////////////////////////////// private methods ////////////////////////////////////////////////////

	protected ArtifactDefinition convertArtifactDataToArtifactDefinition(ArtifactDefinition artifactInfo, ArtifactDataDefinition artifactDefResult) {
		log.debug("The object returned after create property is {}", artifactDefResult);

		ArtifactDefinition propertyDefResult = new ArtifactDefinition(artifactDefResult);
		if (artifactInfo != null)
			propertyDefResult.setPayload(artifactInfo.getPayloadData());

		List<HeatParameterDefinition> parameters = new ArrayList<HeatParameterDefinition>();
		/*
		 * StorageOperationStatus heatParametersOfNode = heatParametersOperation.getHeatParametersOfNode(NodeTypeEnum.ArtifactRef, artifactDefResult.getUniqueId().toString(), parameters); if ((heatParametersOfNode.equals(StorageOperationStatus.OK))
		 * && !parameters.isEmpty()) { propertyDefResult.setHeatParameters(parameters); }
		 */
		return propertyDefResult;
	}

	private ArtifactDataDefinition getInstanceArtifactByLabelAndId(String parentId, String id, String containerId, EdgeLabelEnum edgeLabelEnum) {
		ArtifactDataDefinition foundArtifact = null;
		Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> artifactsEither = getDataFromGraph(containerId, edgeLabelEnum);
		if (artifactsEither.isRight()) {
			log.debug("failed to fetch {} for tosca element with id {}, error {}", edgeLabelEnum, containerId, artifactsEither.right().value());
			return null;
		}

		Map<String, MapArtifactDataDefinition> artifacts = artifactsEither.left().value();

		MapArtifactDataDefinition artifactsPerInstance = artifacts.get(parentId);
		if (artifactsPerInstance == null) {
			log.debug("failed to fetch artifacts for instance {} in tosca element with id {}, error {}", parentId, containerId, artifactsEither.right().value());
			return null;
		}
		Optional<ArtifactDataDefinition> op = artifactsPerInstance.getMapToscaDataDefinition().values().stream().filter(p -> p.getUniqueId().equals(id)).findAny();
		if (op.isPresent()) {
			foundArtifact = op.get();
		}
		return foundArtifact;
	}

	private ArtifactDataDefinition getArtifactByLabelAndId(String parentId, String id, EdgeLabelEnum edgeLabelEnum) {
		ArtifactDataDefinition foundArtifact = null;
		Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> artifactsEither = getDataFromGraph(parentId, edgeLabelEnum);
		if (artifactsEither.isRight()) {
			log.debug("failed to fetch {} for tosca element with id {}, error {}", edgeLabelEnum, parentId, artifactsEither.right().value());
			return null;
		}

		Map<String, ArtifactDataDefinition> artifacts = artifactsEither.left().value();
		Optional<ArtifactDataDefinition> op = artifacts.values().stream().filter(p -> p.getUniqueId().equals(id)).findAny();
		if (op.isPresent()) {
			foundArtifact = op.get();
		}
		return foundArtifact;
	}

	private Either<Map<String, ArtifactDefinition>, TitanOperationStatus> getArtifactByLabel(String parentId, String instanceId, EdgeLabelEnum edgeLabelEnum) {

		Map<String, ArtifactDefinition> artMap = null;
		Map<String, ArtifactDataDefinition> artifactDataMap = null;
		
		if (edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) {
			Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> resultEither = getDataFromGraph(parentId, edgeLabelEnum);
			if (resultEither.isRight()) {
				log.debug("failed to fetch {} for tosca element with id {}, error {}", edgeLabelEnum, parentId, resultEither.right().value());
				return Either.right(resultEither.right().value());
			}
			artifactDataMap = resultEither.left().value();
		}else{
			Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultEither = getDataFromGraph(parentId, edgeLabelEnum);
			if (resultEither.isRight()) {
				log.debug("failed to fetch {} for tosca element with id {}, error {}", edgeLabelEnum, parentId, resultEither.right().value());
				return Either.right(resultEither.right().value());
			}
			Map<String, MapArtifactDataDefinition> mapArtifacts = resultEither.left().value();
			MapArtifactDataDefinition artifactPerInstance = mapArtifacts.get(instanceId);
			if ( artifactPerInstance != null ){
				artifactDataMap = artifactPerInstance.getMapToscaDataDefinition();
			}
		}
		if (artifactDataMap != null && !artifactDataMap.isEmpty()) {
			artMap = artifactDataMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> convertArtifactDataToArtifactDefinition(null, e.getValue())));
		}else{
			artMap = new HashMap<>();
		}
		return Either.left(artMap);

	}

	private Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> getEdgeLabelEnumFromArtifactGroupType(ArtifactGroupTypeEnum groupType, NodeTypeEnum nodeType) {
		EdgeLabelEnum edgeLabelEnum;
		VertexTypeEnum vertexTypeEnum;
		Boolean isDeepElement = false;
		/*
		 * if (nodeType == NodeTypeEnum.ResourceInstance) { edgeLabelEnum = EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS; vertexTypeEnum = VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS; isDeepElement = true; } else {
		 */
		switch (groupType) {
		case TOSCA:
			edgeLabelEnum = EdgeLabelEnum.TOSCA_ARTIFACTS;
			vertexTypeEnum = VertexTypeEnum.TOSCA_ARTIFACTS;
			break;
		case DEPLOYMENT:
			if (nodeType == NodeTypeEnum.ResourceInstance) {
				edgeLabelEnum = EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS;
				vertexTypeEnum = VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS;
				isDeepElement = true;
			} else {
				edgeLabelEnum = EdgeLabelEnum.DEPLOYMENT_ARTIFACTS;
				vertexTypeEnum = VertexTypeEnum.DEPLOYMENT_ARTIFACTS;
			}
			break;
		case SERVICE_API:
			edgeLabelEnum = EdgeLabelEnum.SERVICE_API_ARTIFACTS;
			vertexTypeEnum = VertexTypeEnum.SERVICE_API_ARTIFACTS;
			break;
		default:
			if (nodeType == NodeTypeEnum.ResourceInstance) {
				edgeLabelEnum = EdgeLabelEnum.INSTANCE_ARTIFACTS;
				vertexTypeEnum = VertexTypeEnum.INSTANCE_ARTIFACTS;
				isDeepElement = true;
			} else {
				edgeLabelEnum = EdgeLabelEnum.ARTIFACTS;
				vertexTypeEnum = VertexTypeEnum.ARTIFACTS;
			}
			break;
		}
		// }
		return new ImmutableTriple<EdgeLabelEnum, Boolean, VertexTypeEnum>(edgeLabelEnum, isDeepElement, vertexTypeEnum);

	}

	public Either<ArtifactDataDefinition, StorageOperationStatus> updateArtifactOnGraph(String componentId, ArtifactDefinition artifactInfo, NodeTypeEnum type, String artifactId, String instanceId, boolean isUpdate) {
		Either<ArtifactDataDefinition, StorageOperationStatus> res = null;
		ArtifactDataDefinition artifactToUpdate = new ArtifactDataDefinition(artifactInfo);
		ArtifactGroupTypeEnum groupType = artifactInfo.getArtifactGroupType();

		Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> triple = getEdgeLabelEnumFromArtifactGroupType(groupType, type);
		EdgeLabelEnum edgeLabelEnum = triple.getLeft();
		VertexTypeEnum vertexTypeEnum = triple.getRight();

		Either<Boolean, StorageOperationStatus> isNeedToCloneEither = isCloneNeeded(componentId, edgeLabelEnum);
		if (isNeedToCloneEither.isRight()) {
			log.debug("Failed check is clone needed {}", componentId);
			return Either.right(isNeedToCloneEither.right().value());

		}
		boolean isNeedToClone = isNeedToCloneEither.left().value();

		if (artifactId == null || isNeedToClone) {
			String uniqueId;
			if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) {
				uniqueId = UniqueIdBuilder.buildPropertyUniqueId(componentId, artifactToUpdate.getArtifactLabel());
			} else {
				uniqueId = UniqueIdBuilder.buildPropertyUniqueId(instanceId, artifactToUpdate.getArtifactLabel());
			}
			artifactToUpdate.setUniqueId(uniqueId);

		} else
			artifactToUpdate.setUniqueId(artifactId);

		Map<String, ArtifactDataDefinition> artifacts = null;
		if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) {

			Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> artifactsEither = this.getDataFromGraph(componentId, edgeLabelEnum);

			if (artifactsEither.isLeft() && artifactsEither.left().value() != null && !artifactsEither.left().value().isEmpty()) {
				artifacts = artifactsEither.left().value();
				if (isNeedToClone) {
					artifacts.values().stream().forEach(a -> a.setDuplicated(Boolean.TRUE));
				}
			}
		} else {
			Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> artifactsEither = this.getDataFromGraph(componentId, edgeLabelEnum);
			if (artifactsEither.isLeft()) {
				Map<String, MapArtifactDataDefinition> artifactInst = artifactsEither.left().value();
				if (isNeedToClone) {
					artifactInst.values().forEach(ma -> ma.getMapToscaDataDefinition().values().forEach(a -> a.setDuplicated(Boolean.TRUE)));
				}
				MapArtifactDataDefinition artifatcsOnInstance = artifactInst.get(instanceId);
				if (artifatcsOnInstance != null) {
					artifacts = artifatcsOnInstance.getMapToscaDataDefinition();
				}
			}
		}
		String oldChecksum = null;
		String oldVersion = null;
		if (artifacts != null && artifacts.containsKey(artifactInfo.getArtifactLabel())) {
			ArtifactDataDefinition oldArtifactData = artifacts.get(artifactInfo.getArtifactLabel());
			oldChecksum = oldArtifactData.getArtifactChecksum();
			oldVersion = oldArtifactData.getArtifactVersion();
			if (isNeedToClone)
				artifactToUpdate.setDuplicated(Boolean.FALSE);
			else {
				if (artifactToUpdate.getDuplicated()) {
					String id = type != NodeTypeEnum.ResourceInstance ? componentId : instanceId;
					String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(id, artifactToUpdate.getArtifactLabel());
					artifactToUpdate.setUniqueId(uniqueId);
					artifactToUpdate.setDuplicated(Boolean.TRUE);
				}
			}
		}
		updateUUID(artifactToUpdate, oldChecksum, oldVersion, isUpdate);

		if (artifactInfo.getPayloadData() == null) {
			if (!artifactToUpdate.getMandatory() || artifactToUpdate.getEsId() != null) {
				artifactToUpdate.setEsId(artifactToUpdate.getUniqueId());
			}
		} else {
			if (artifactToUpdate.getEsId() == null) {
				artifactToUpdate.setEsId(artifactToUpdate.getUniqueId());

			}
		}

		StorageOperationStatus status;
		if (edgeLabelEnum != EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS && edgeLabelEnum != EdgeLabelEnum.INSTANCE_ARTIFACTS) {
			status = updateToscaDataOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, artifactToUpdate, JsonPresentationFields.ARTIFACT_LABEL);
		} else {
			List<String> pathKeys = new ArrayList<>();
			pathKeys.add(instanceId);
			List<ArtifactDataDefinition> toscaDataList = new ArrayList<>();
			toscaDataList.add(artifactToUpdate);
			status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataList, pathKeys, JsonPresentationFields.ARTIFACT_LABEL);
		}
		if (status == StorageOperationStatus.OK)
			res = Either.left(artifactToUpdate);
		else
			res = Either.right(status);
		return res;
	}

	public void generateUUID(ArtifactDataDefinition artifactData, String oldVesrion) {

		UUID uuid = UUID.randomUUID();
		artifactData.setArtifactUUID(uuid.toString());
		MDC.put("serviceInstanceID", uuid.toString());
		updateVersionAndDate(artifactData, oldVesrion);
	}

	private void updateVersionAndDate(ArtifactDataDefinition artifactData, String oldVesrion) {
		if (artifactData.getArtifactChecksum() != null) {
			long time = System.currentTimeMillis();
			artifactData.setPayloadUpdateDate(time);
		}
		int newVersion = new Integer(oldVesrion).intValue();
		newVersion++;
		artifactData.setArtifactVersion(String.valueOf(newVersion));
	}

	private boolean validateParentType(NodeTypeEnum type) {
		boolean isValid = false;
		switch (type) {
		case Resource:
		case InterfaceOperation:
		case Service:
		case ResourceInstance:
			isValid = true;
			break;
		default:
			log.debug("Not supported node type for artifact relation : {} ", type);
		}
		return isValid;
	}

	public Either<ArtifactDataDefinition, StorageOperationStatus> removeArtifactOnGraph(ArtifactDefinition artifactFromGraph, String componentId, String instanceId, NodeTypeEnum type, boolean deleteMandatoryArtifact) {

		Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> triple = getEdgeLabelEnumFromArtifactGroupType(artifactFromGraph.getArtifactGroupType(), type);
		EdgeLabelEnum edgeLabelEnum = triple.getLeft();
		VertexTypeEnum vertexTypeEnum = triple.getRight();

		if (deleteMandatoryArtifact || !(artifactFromGraph.getMandatory() || artifactFromGraph.getServiceApi())) {
			StorageOperationStatus status;
			if (triple.getMiddle()) {
				List<String> pathKeys = new ArrayList<>();
				pathKeys.add(instanceId);
				status = deleteToscaDataDeepElement(componentId, edgeLabelEnum, vertexTypeEnum, artifactFromGraph.getArtifactLabel(), pathKeys, JsonPresentationFields.ARTIFACT_LABEL);
			} else {
				status = deleteToscaDataElement(componentId, edgeLabelEnum, vertexTypeEnum, artifactFromGraph.getArtifactLabel(), JsonPresentationFields.ARTIFACT_LABEL);
			}
			if (status != StorageOperationStatus.OK)
				return Either.right(status);
		}
		return Either.left(artifactFromGraph);

	}

	public Either<ArtifactDataDefinition, StorageOperationStatus> deleteArtifactWithClonnigOnGraph(String componentId, ArtifactDefinition artifactToDelete, NodeTypeEnum type, String instanceId, boolean deleteMandatoryArtifact) {

		Either<ArtifactDataDefinition, StorageOperationStatus> result = null;
		Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> triple = getEdgeLabelEnumFromArtifactGroupType(artifactToDelete.getArtifactGroupType(), type);
		EdgeLabelEnum edgeLabel = triple.getLeft();
		VertexTypeEnum vertexLabel = triple.getRight();

		Boolean deleteElement = deleteMandatoryArtifact || !(artifactToDelete.getMandatory() || artifactToDelete.getServiceApi());
		Map<String, ToscaDataDefinition> artifacts = null;
		GraphVertex parentVertex = null;
		Either<Map<String, ToscaDataDefinition>, TitanOperationStatus> getArtifactsRes = null;

		Either<GraphVertex, TitanOperationStatus> getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
		if (getToscaElementRes.isRight()) {
			CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get tosca element {} upon getting tosca data from graph. Status is {}. ", componentId, getToscaElementRes.right().value());
			result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getToscaElementRes.right().value()));
		}
		if (result == null) {
			parentVertex = getToscaElementRes.left().value();
			getArtifactsRes = this.getDataFromGraph(parentVertex, edgeLabel);
			if (getArtifactsRes.isRight()) {
				result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getArtifactsRes.right().value()));
			}
		}
		if (result == null) {
			artifacts = getArtifactsRes.left().value();
			if (triple.getMiddle()) {
				artifacts.values().forEach(ma -> ((MapArtifactDataDefinition) ma).getMapToscaDataDefinition().values().forEach(a -> a.setDuplicated(Boolean.TRUE)));
				MapArtifactDataDefinition artifatcsOnInstance = (MapArtifactDataDefinition) artifacts.get(instanceId);
				if (artifatcsOnInstance != null && deleteElement) {
					artifatcsOnInstance.getMapToscaDataDefinition().remove(artifactToDelete.getArtifactLabel());
				}
			} else {
				if (deleteElement) {
					artifacts.remove(artifactToDelete.getArtifactLabel());
				}
				artifacts.values().stream().forEach(a -> ((ArtifactDataDefinition) a).setDuplicated(Boolean.TRUE));
			}
			artifactToDelete.setDuplicated(Boolean.TRUE);
		}
		if (artifacts != null) {
			TitanOperationStatus status = titanDao.deleteEdgeByDirection(parentVertex, Direction.OUT, edgeLabel);
			if (status != TitanOperationStatus.OK) {
				result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
			} else if (MapUtils.isNotEmpty(artifacts)) {
				Either<GraphVertex, StorageOperationStatus> assosiateRes = assosiateElementToData(parentVertex, vertexLabel, edgeLabel, artifacts);
				if (assosiateRes.isRight()) {
					result = Either.right(result.right().value());
				}
			}
		}
		if (result == null) {
			result = Either.left(artifactToDelete);
		}
		return result;
	}
}