9965a05294b803c9f738ca76debcb7e836da3376
[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     public ResourceStructure(INotificationData notificationData, IResourceInstance resourceInstance) {
72         this.notificationData = notificationData;
73         this.resourceInstance = resourceInstance;
74         artifactsMapByUUID = new HashMap<>();
75     }
76
77     /**
78      * Add artifact to the resource structure.
79      *
80      * @param distributionClient
81      * @param artifactinfo
82      * @param clientResult
83      * @throws UnsupportedEncodingException
84      */
85     public abstract void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo,
86             IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException;
87
88     /**
89      * Prepare the resource for installation.
90      *
91      * @throws ArtifactInstallerException
92      */
93     public abstract void prepareInstall() throws ArtifactInstallerException;
94
95     public boolean isDeployedSuccessfully() {
96         return isDeployedSuccessfully;
97     }
98
99     public void setDeployedSuccessfully(boolean deployedSuccessfully) {
100         isDeployedSuccessfully = deployedSuccessfully;
101     }
102
103     public boolean isAlreadyDeployed() {
104         return isAlreadyDeployed;
105     }
106
107     public void setAlreadyDeployed(boolean alreadyDeployed) {
108         isAlreadyDeployed = alreadyDeployed;
109     }
110
111     public ResourceType getResourceType() {
112         return resourceType;
113     }
114
115     public void setResourceType(ResourceType resourceType) {
116         this.resourceType = resourceType;
117     }
118
119     public INotificationData getNotification() {
120         return notificationData;
121     }
122
123     public void setNotification(INotificationData notificationData) {
124         this.notificationData = notificationData;
125     }
126
127     public IResourceInstance getResourceInstance() {
128         return resourceInstance;
129     }
130
131     public void setResourceInstance(IResourceInstance resourceInstance) {
132         this.resourceInstance = resourceInstance;
133     }
134
135     public int getNumberOfResources() {
136         return NumberOfResources;
137     }
138
139     public void setNumberOfResources(int numberOfResources) {
140         NumberOfResources = numberOfResources;
141     }
142
143     public Map<String, VfModuleArtifact> getArtifactsMapByUUID() {
144         return artifactsMapByUUID;
145     }
146
147 }