PNF ingestion in SO catalogdb
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / installer / ResourceStructure.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.so.asdc.installer;
21
22 import java.io.UnsupportedEncodingException;
23 import java.util.HashMap;
24 import java.util.Map;
25 import org.onap.sdc.api.IDistributionClient;
26 import org.onap.sdc.api.notification.IArtifactInfo;
27 import org.onap.sdc.api.notification.INotificationData;
28 import org.onap.sdc.api.notification.IResourceInstance;
29 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
30 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * Abstract class to represent the resource structure.
36  *
37  * This structure exists to avoid having issues if the order of the resource artifact of tree structure is not good.
38  */
39 public abstract class ResourceStructure {
40
41     /**
42      * Flag to indicate whether the resource is deployed successfully.
43      */
44     protected boolean isDeployedSuccessfully = false;
45
46     /**
47      * Flag to indicate whether the resource is already deployed.
48      */
49     protected boolean isAlreadyDeployed = false;
50
51     /**
52      * The resource type.
53      */
54     protected ResourceType resourceType;
55
56     /**
57      * The Raw notification data.
58      */
59     protected INotificationData notificationData;
60
61     /**
62      * The resource we will try to deploy.
63      */
64     protected IResourceInstance resourceInstance;
65
66     /**
67      * Number of resources provided by the resource structure.
68      */
69     protected int NumberOfResources;
70
71     /**
72      * The list of artifacts existing in this resource hashed by UUID.
73      */
74     protected final Map<String, VfModuleArtifact> artifactsMapByUUID;
75
76     public ResourceStructure(INotificationData notificationData, IResourceInstance resourceInstance) {
77         this.notificationData = notificationData;
78         this.resourceInstance = resourceInstance;
79         artifactsMapByUUID = new HashMap<>();
80     }
81
82     /**
83      * Add artifact to the resource structure.
84      *
85      * @param distributionClient
86      * @param artifactinfo
87      * @param clientResult
88      * @throws UnsupportedEncodingException
89      */
90     public abstract void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo,
91         IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException;
92
93     /**
94      * Prepare the resource for installation.
95      *
96      * @throws ArtifactInstallerException
97      */
98     public abstract void prepareInstall() throws ArtifactInstallerException;
99
100     public boolean isDeployedSuccessfully() {
101         return isDeployedSuccessfully;
102     }
103
104     public void setDeployedSuccessfully(boolean deployedSuccessfully) {
105         isDeployedSuccessfully = deployedSuccessfully;
106     }
107
108     public boolean isAlreadyDeployed() {
109         return isAlreadyDeployed;
110     }
111
112     public void setAlreadyDeployed(boolean alreadyDeployed) {
113         isAlreadyDeployed = alreadyDeployed;
114     }
115
116     public ResourceType getResourceType() {
117         return resourceType;
118     }
119
120     public void setResourceType(ResourceType resourceType) {
121         this.resourceType = resourceType;
122     }
123
124     public INotificationData getNotification() {
125         return notificationData;
126     }
127
128     public void setNotification(INotificationData notificationData) {
129         this.notificationData = notificationData;
130     }
131
132     public IResourceInstance getResourceInstance() {
133         return resourceInstance;
134     }
135
136     public void setResourceInstance(IResourceInstance resourceInstance) {
137         this.resourceInstance = resourceInstance;
138     }
139
140     public int getNumberOfResources() {
141         return NumberOfResources;
142     }
143
144     public void setNumberOfResources(int numberOfResources) {
145         NumberOfResources = numberOfResources;
146     }
147
148     public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
149         return artifactsMapByUUID;
150     }
151
152 }