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