2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model.cache.jobs;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
25 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
26 import org.openecomp.sdc.be.model.Component;
27 import org.openecomp.sdc.be.model.cache.DaoInfo;
28 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
29 import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
30 import org.openecomp.sdc.common.log.wrappers.Logger;
32 public abstract class Job<E> {
33 private static final Logger log = Logger.getLogger(Job.class.getName());
34 protected DaoInfo daoInfo;
35 protected String componentId;
36 protected long timestamp;
37 protected NodeTypeEnum nodeTypeEnum;
39 protected Job(DaoInfo daoInfo, String componentId, NodeTypeEnum nodeTypeEnum, long timestamp) {
40 this.daoInfo = daoInfo;
41 this.componentId = componentId;
42 this.timestamp = timestamp;
43 this.nodeTypeEnum = nodeTypeEnum;
46 protected Job(DaoInfo daoInfo, Component component, NodeTypeEnum nodeTypeEnum) {
47 this.daoInfo = daoInfo;
48 this.componentId = component.getUniqueId();
49 this.timestamp = component.getLastUpdateDate();
50 this.nodeTypeEnum = nodeTypeEnum;
53 public abstract E doWork();
55 protected Either<ComponentMetadataData, StorageOperationStatus> getComponentMetaData(String componentId,
56 NodeTypeEnum nodeTypeEnum) {
57 Either<ComponentMetadataData, StorageOperationStatus> metaDataRes = daoInfo.getToscaOperationFacade().getComponentMetadata(componentId);
58 if (metaDataRes.isRight()) {
59 // in case we cant find the component on graph exit
60 if (StorageOperationStatus.NOT_FOUND.equals(metaDataRes.right().value())) {
61 log.debug("failed to locate component:{} on graph status:{}", componentId, metaDataRes.right().value());
63 log.debug("failed to get component:{} from graph status:{}", componentId, metaDataRes.right().value());
69 protected NodeTypeEnum getNodeTypeFromComponentType(ComponentTypeEnum type) {
70 NodeTypeEnum result = null;
73 result = NodeTypeEnum.Product;
76 result = NodeTypeEnum.Resource;
79 result = NodeTypeEnum.Service;