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.operations.impl;
23 import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
24 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
25 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
26 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
27 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
28 import org.openecomp.sdc.common.log.wrappers.Logger;
29 import org.springframework.stereotype.Component;
31 @Component("graph-lock-operation")
32 public class GraphLockOperation implements IGraphLockOperation {
33 private static final Logger log = Logger.getLogger(GraphLockOperation.class.getName());
35 @javax.annotation.Resource
36 private TitanGenericDao titanGenericDao;
38 public GraphLockOperation() {
45 * @see org.openecomp.sdc.be.model.operations.impl.IGraphLockOperation# lockResource(java.lang.String, org.openecomp.sdc.be.model.operations.api.IResourceOperation)
48 public StorageOperationStatus lockComponent(String componentId, NodeTypeEnum nodeType) {
49 log.info("lock resource with id {}", componentId);
50 TitanOperationStatus lockElementStatus = null;
52 lockElementStatus = titanGenericDao.lockElement(componentId, nodeType);
53 } catch (Exception e) {
54 lockElementStatus = TitanOperationStatus.ALREADY_LOCKED;
58 return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);
65 * @see org.openecomp.sdc.be.model.operations.impl.IGraphLockOperation# unlockResource(java.lang.String, org.openecomp.sdc.be.model.operations.api.IResourceOperation)
68 public StorageOperationStatus unlockComponent(String componentId, NodeTypeEnum nodeType) {
69 TitanOperationStatus lockElementStatus = titanGenericDao.releaseElement(componentId, nodeType);
70 return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);
74 public StorageOperationStatus unlockComponentByName(String name, String componentId, NodeTypeEnum nodeType) {
75 TitanOperationStatus lockElementStatus = titanGenericDao.releaseElement(name, nodeType);
76 return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);
80 public StorageOperationStatus lockComponentByName(String name, NodeTypeEnum nodeType) {
81 log.info("lock resource with name {}", name);
82 TitanOperationStatus lockElementStatus = null;
85 lockElementStatus = titanGenericDao.lockElement(name, nodeType);
87 } catch (Exception e) {
88 lockElementStatus = TitanOperationStatus.ALREADY_LOCKED;
92 return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);