AT&T 1712 and 1802 release code
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / cloud / CloudifyManager.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.mso.cloud;
22
23 import java.security.GeneralSecurityException;
24
25 import com.fasterxml.jackson.annotation.JsonProperty;
26
27 import org.openecomp.mso.utils.CryptoUtils;
28 import org.openecomp.mso.logger.MessageEnum;
29 import org.openecomp.mso.logger.MsoLogger;
30
31 /**
32  * JavaBean JSON class for a Cloudify Manager.  This bean represents a Cloudify
33  * node through which TOSCA-based VNFs may be deployed.  Each CloudSite in the
34  * CloudConfig may have a Cloudify Manager for deployments using TOSCA blueprints.
35  * Cloudify Managers may support multiple Cloud Sites, but each site will have
36  * at most one Cloudify Manager.
37  * 
38  * This does not replace the ability to use the CloudSite directly via Openstack.
39  *
40  * Note that this is only used to access Cloud Configurations loaded from a
41  * JSON config file, so there are no explicit setters.
42  *
43  * @author JC1348
44  */
45 public class CloudifyManager {
46         
47     private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
48
49         @JsonProperty
50         private String id;
51         @JsonProperty ("cloudify_url")
52         private String cloudifyUrl;
53         @JsonProperty("username")
54         private String username;
55         @JsonProperty("password")
56         private String password;
57         @JsonProperty("version")
58         private String version;
59
60     private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f";
61
62         public CloudifyManager() {}
63         
64         public String getId() {
65                 return id;
66         }
67         public void setId(String id) {
68                 this.id = id;
69         }
70         
71         public String getCloudifyUrl() {
72                 return cloudifyUrl;
73         }
74
75         public void setCloudifyUrl(String cloudifyUrl) {
76                 this.cloudifyUrl = cloudifyUrl;
77         }
78
79         public String getUsername() {
80                 return username;
81         }
82
83         public void setUsername(String username) {
84                 this.username = username;
85         }
86
87         public String getPassword() {
88         try {
89             return CryptoUtils.decrypt (password, cloudKey);
90         } catch (GeneralSecurityException e) {
91             LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in getMsoPass", e);
92             return null;
93         }
94         }
95
96         public void setPassword(String password) {
97                 this.password = password;
98         }
99
100         public String getVersion() {
101                 return version;
102         }
103
104         public void setVersion(String version) {
105                 this.version = version;
106         }
107
108
109         @Override
110         public String toString() {
111                 return "CloudifyManager: id=" + id +
112                         ", cloudifyUrl=" + cloudifyUrl +
113                         ", username=" + username +
114                         ", password=" + password +
115                         ", version=" + version;
116         }
117
118         @Override
119         public CloudifyManager clone() {
120                 CloudifyManager cloudifyManagerCopy = new CloudifyManager();
121                 cloudifyManagerCopy.id = this.id;
122                 cloudifyManagerCopy.cloudifyUrl = this.cloudifyUrl;
123                 cloudifyManagerCopy.username = this.username;
124                 cloudifyManagerCopy.password = this.password;
125                 cloudifyManagerCopy.version = this.version;
126                 return cloudifyManagerCopy;
127         }
128
129         @Override
130         public int hashCode() {
131                 final int prime = 31;
132                 int result = 1;
133                 result = prime * result + ((id == null) ? 0 : id.hashCode());
134                 result = prime * result + ((cloudifyUrl == null) ? 0 : cloudifyUrl.hashCode());
135                 result = prime * result + ((username == null) ? 0 : username.hashCode());
136                 result = prime * result + ((password == null) ? 0 : password.hashCode());
137                 result = prime * result + ((version == null) ? 0 : version.hashCode());
138                 return result;
139         }
140
141         @Override
142         public boolean equals(Object obj) {
143                 if (this == obj)
144                         return true;
145                 if (obj == null)
146                         return false;
147                 if (getClass() != obj.getClass())
148                         return false;
149                 CloudifyManager other = (CloudifyManager) obj;
150                 if (!cmp(id, other.id))
151                         return false;
152                 if (!cmp(cloudifyUrl, other.cloudifyUrl))
153                         return false;
154                 if (!cmp(username, other.username))
155                         return false;
156                 if (!cmp(version, other.version))
157                         return false;
158                 if (!cmp(password, other.password))
159                         return false;
160                 return true;
161         }
162         private boolean cmp(Object a, Object b) {
163                 if (a == null) {
164                         return (b == null);
165                 } else {
166                         return a.equals(b);
167                 }
168         }
169 }