82d22addf3f672ca81b27075d1f84545b3ea3f2a
[sdc.git] /
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.asdctool.impl.migration.v1707.jsonmodel;
22
23 import java.util.List;
24
25 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
26 import org.openecomp.sdc.be.model.Resource;
27 import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import fj.data.Either;
32
33 public class VFResourcesMigration extends ComponentMigration<Resource> {
34
35     private static Logger LOGGER = LoggerFactory.getLogger(VFResourcesMigration.class);
36
37     @javax.annotation.Resource(name = "resource-operation")
38     private IResourceOperation resourceOperation;
39
40     @javax.annotation.Resource(name = "resource-version-migration")
41     private VersionMigration<Resource> versionMigration;
42
43     @Override
44     public String description() {
45         return "migrate VFs";
46     }
47
48     @Override
49     Either<List<Resource>, ?> getElementsToMigrate() {
50         return resourceOperation.getVFResources();
51     }
52
53     @Override
54     boolean save(Resource element) {
55         requirementsCapabilitiesMigrationService.overrideInstanceCapabilitiesRequirements(element);
56         return super.save(element);
57     }
58
59     @Override
60     boolean doPostSaveOperation(Resource element) {
61         return element.getComponentInstances() == null ||
62                 (requirementsCapabilitiesMigrationService.associateFulfilledRequirements(element, NodeTypeEnum.Resource) &&
63                  requirementsCapabilitiesMigrationService.associateFulfilledCapabilities(element, NodeTypeEnum.Resource));
64     }
65
66     @Override
67     boolean doPostMigrateOperation(List<Resource> elements) {
68         LOGGER.info("migrating VFs versions");
69         return versionMigration.buildComponentsVersionChain(elements);
70     }
71
72     @Override
73     void doPreMigrationOperation(List<Resource> elements) {
74         super.doPreMigrationOperation(elements);
75         setMissingTemplateInfo(elements);
76     }
77
78
79 }