re base code
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / operations / impl / GraphLockOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.operations.impl;
22
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;
30
31 @Component("graph-lock-operation")
32 public class GraphLockOperation implements IGraphLockOperation {
33     private static final Logger log = Logger.getLogger(GraphLockOperation.class.getName());
34
35     @javax.annotation.Resource
36     private TitanGenericDao titanGenericDao;
37
38     public GraphLockOperation() {
39         super();
40     }
41
42     /*
43      * (non-Javadoc)
44      *
45      * @see org.openecomp.sdc.be.model.operations.impl.IGraphLockOperation# lockResource(java.lang.String, org.openecomp.sdc.be.model.operations.api.IResourceOperation)
46      */
47     @Override
48     public StorageOperationStatus lockComponent(String componentId, NodeTypeEnum nodeType) {
49         log.info("lock resource with id {}", componentId);
50         TitanOperationStatus lockElementStatus = null;
51         try {
52             lockElementStatus = titanGenericDao.lockElement(componentId, nodeType);
53         } catch (Exception e) {
54             lockElementStatus = TitanOperationStatus.ALREADY_LOCKED;
55
56         }
57
58         return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);
59
60     }
61
62     /*
63      * (non-Javadoc)
64      *
65      * @see org.openecomp.sdc.be.model.operations.impl.IGraphLockOperation# unlockResource(java.lang.String, org.openecomp.sdc.be.model.operations.api.IResourceOperation)
66      */
67     @Override
68     public StorageOperationStatus unlockComponent(String componentId, NodeTypeEnum nodeType) {
69         TitanOperationStatus lockElementStatus = titanGenericDao.releaseElement(componentId, nodeType);
70         return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);
71     }
72
73     @Override
74     public StorageOperationStatus unlockComponentByName(String name, String componentId, NodeTypeEnum nodeType) {
75         TitanOperationStatus lockElementStatus = titanGenericDao.releaseElement(name, nodeType);
76         return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);
77     }
78
79     @Override
80     public StorageOperationStatus lockComponentByName(String name, NodeTypeEnum nodeType) {
81         log.info("lock resource with name {}", name);
82         TitanOperationStatus lockElementStatus = null;
83         try {
84
85             lockElementStatus = titanGenericDao.lockElement(name, nodeType);
86
87         } catch (Exception e) {
88             lockElementStatus = TitanOperationStatus.ALREADY_LOCKED;
89
90         }
91
92         return DaoStatusConverter.convertTitanStatusToStorageStatus(lockElementStatus);
93
94     }
95 }