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.janusgraph.JanusGraphGenericDao;
24 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
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 JanusGraphGenericDao janusGraphGenericDao;
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 JanusGraphOperationStatus lockElementStatus = null;
52 lockElementStatus = janusGraphGenericDao.lockElement(componentId, nodeType);
53 } catch (Exception e) {
54 lockElementStatus = JanusGraphOperationStatus.ALREADY_LOCKED;
58 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(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 JanusGraphOperationStatus lockElementStatus = janusGraphGenericDao
70 .releaseElement(componentId, nodeType);
71 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(lockElementStatus);
75 public StorageOperationStatus unlockComponentByName(String name, String componentId, NodeTypeEnum nodeType) {
76 JanusGraphOperationStatus
77 lockElementStatus = janusGraphGenericDao.releaseElement(name, nodeType);
78 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(lockElementStatus);
82 public StorageOperationStatus lockComponentByName(String name, NodeTypeEnum nodeType) {
83 log.info("lock resource with name {}", name);
84 JanusGraphOperationStatus lockElementStatus = null;
87 lockElementStatus = janusGraphGenericDao.lockElement(name, nodeType);
89 } catch (Exception e) {
90 lockElementStatus = JanusGraphOperationStatus.ALREADY_LOCKED;
94 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(lockElementStatus);