diff options
Diffstat (limited to 'vid-app-common/src/main/java/org')
50 files changed, 2599 insertions, 1011 deletions
diff --git a/vid-app-common/src/main/java/org/openecomp/aai/util/AAIProperties.java b/vid-app-common/src/main/java/org/openecomp/aai/util/AAIProperties.java index ca710f6fc..9716ba827 100755 --- a/vid-app-common/src/main/java/org/openecomp/aai/util/AAIProperties.java +++ b/vid-app-common/src/main/java/org/openecomp/aai/util/AAIProperties.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/aai/util/AAIRestInterface.java b/vid-app-common/src/main/java/org/openecomp/aai/util/AAIRestInterface.java index cd5095191..243410050 100755 --- a/vid-app-common/src/main/java/org/openecomp/aai/util/AAIRestInterface.java +++ b/vid-app-common/src/main/java/org/openecomp/aai/util/AAIRestInterface.java @@ -276,43 +276,22 @@ public class AAIRestInterface { if (xml)
responseType = "application/xml";
- initRestClient();
-
- String clientCert = SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT);
-
- boolean useClientCert = false;
- if (clientCert != null &&
- SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT).equalsIgnoreCase("true")) {
- useClientCert = true;
- }
+ initRestClient();
url = SystemProperties.getProperty(AAIProperties.AAI_SERVER_URL_BASE) + path;
- final Response cres;
- if (useClientCert == true) {
- cres = client.target(url)
- .request()
- .accept(responseType)
- .header("X-TransactionId", transId)
- .header("X-FromAppId", fromAppId)
- .header("Content-Type", "application/json")
- .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
- } else {
-
- String vidUsername = SystemProperties.getProperty(AAIProperties.AAI_VID_USERNAME);
- String vidPassword = Password.deobfuscate(SystemProperties.getProperty(AAIProperties.AAI_VID_PASSWD_X));
- String encodeThis = vidUsername + ":" + vidPassword;
-
- cres = client.target(url)
- .request()
- .accept(responseType)
- .header("X-TransactionId", transId)
- .header("X-FromAppId", fromAppId)
- .header("Content-Type", "application/json")
- .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(encodeThis.getBytes("utf-8")))
- .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
- }
-
+ String vidUsername = SystemProperties.getProperty(AAIProperties.AAI_VID_USERNAME);
+ String vidPassword = Password.deobfuscate(SystemProperties.getProperty(AAIProperties.AAI_VID_PASSWD_X));
+ String encodeThis = vidUsername + ":" + vidPassword;
+
+ final Response cres = client.target(url)
+ .request()
+ .accept(responseType)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", fromAppId)
+ .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(encodeThis.getBytes("utf-8")))
+ .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
+
if (cres.getStatus() == 200 && cres.getStatus() <= 299) {
logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " REST api POST was successful!");
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " REST api POST was successful!");
diff --git a/vid-app-common/src/main/java/org/openecomp/aai/util/CustomJacksonJaxBJsonProvider.java b/vid-app-common/src/main/java/org/openecomp/aai/util/CustomJacksonJaxBJsonProvider.java index 2623d6b6f..1ed079219 100755 --- a/vid-app-common/src/main/java/org/openecomp/aai/util/CustomJacksonJaxBJsonProvider.java +++ b/vid-app-common/src/main/java/org/openecomp/aai/util/CustomJacksonJaxBJsonProvider.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java b/vid-app-common/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java index 8335d15b2..6a3665edb 100755 --- a/vid-app-common/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java +++ b/vid-app-common/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java b/vid-app-common/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java index e4c4bcef1..e31b0c1c7 100755 --- a/vid-app-common/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java +++ b/vid-app-common/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java index aafb11cad..c80787205 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcCatalogException.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java index c4a8b1c0c..314ea037d 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/AsdcClient.java @@ -20,6 +20,8 @@ package org.openecomp.vid.asdc;
+import java.io.IOException;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
@@ -27,7 +29,6 @@ import java.util.UUID; import org.openecomp.vid.asdc.beans.Artifact;
import org.openecomp.vid.asdc.beans.Resource;
import org.openecomp.vid.asdc.beans.Service;
-import org.openecomp.vid.asdc.beans.tosca.ToscaCsar;
/**
* The Interface AsdcClient.
@@ -77,7 +78,7 @@ public interface AsdcClient { * @return the resource tosca model
* @throws AsdcCatalogException the sdc catalog exception
*/
- public ToscaCsar getResourceToscaModel(UUID uuid) throws AsdcCatalogException;
+ public Path getResourceToscaModel(UUID uuid) throws AsdcCatalogException;
/**
* Gets the service.
@@ -122,7 +123,7 @@ public interface AsdcClient { * @return the service tosca model
* @throws AsdcCatalogException the asdc catalog exception
*/
- public ToscaCsar getServiceToscaModel(UUID uuid) throws AsdcCatalogException;
+ public Path getServiceToscaModel(UUID uuid) throws AsdcCatalogException;
//TODO: Collect TOSCA information from CSAR
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java index d24d1232a..4974d44a8 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Artifact.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java index 3911c699a..000aae1a9 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Resource.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java index fa898e56a..2a83cbe3a 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/Service.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java index 6d7fb41b1..cd3ec7fee 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/SubResource.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java index 21a50d3bb..0d3f17ae4 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Capability.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java index b68b51a09..a91f38312 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Constraint.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.vid.asdc.beans.tosca;
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java index 275db3c0d..4d31faab1 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Group.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java index 33f317579..d64a58066 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Import.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java index f98820716..e5eec0121 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Input.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,12 +14,14 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.vid.asdc.beans.tosca;
+import org.openecomp.sdc.toscaparser.api.elements.constraints.*;
+
import java.util.List;
import java.util.ArrayList;
@@ -42,7 +44,7 @@ public class Input { private Input entry_schema;
/** The constraints */
- private List<Constraint> constraints;
+ private List<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint> constraints;
/** The required field. If not set, the default is true */
private boolean required = true;
@@ -51,7 +53,7 @@ public class Input { * Instantiates a new input.
*/
public Input() {
- constraints = new ArrayList<Constraint>();
+ constraints = new ArrayList<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint>();
}
/**
@@ -144,7 +146,7 @@ public class Input { *
* @param c the new constraints
*/
- public void setConstraints(List<Constraint> c) {
+ public void setConstraints(List<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint> c) {
this.constraints = c;
}
/**
@@ -152,7 +154,7 @@ public class Input { *
* @return the constraints
*/
- public List<Constraint> getConstraints() {
+ public List<org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint> getConstraints() {
return constraints;
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java index 73eead93f..97740b3f5 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/NodeTemplate.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java index c8f048ced..16b921e2a 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Property.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java index fce41ec6e..acb250997 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Requirement.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java index bd3a2f0a5..f77c1b4b5 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/Schema.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java index 026f29bbe..f59f24674 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/SubstitutionMappings.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java index ce7ce5755..25b2c2c38 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/TopologyTemplate.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java index cca4ae7c2..9e9e1d00b 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaCsar.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java index 41c7ca5ba..d42c1f150 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaMetadata.java @@ -61,9 +61,6 @@ public class ToscaMetadata { /** The resource vendor release. */
private String resourceVendorRelease;
- /** the resourceVendorModelNumber */
- private String resourceVendorModelNumber;
-
/** The service ecomp naming. */
private String serviceEcompNaming;
@@ -91,11 +88,6 @@ public class ToscaMetadata { /** The vf module model version. */
private String vfModuleModelVersion;
-
- /** serviceType */
- private String serviceType;
- /** serviceRole */
- private String serviceRole;
/**
* Instantiates a new tosca metadata.
@@ -466,26 +458,4 @@ public class ToscaMetadata { return vfModuleModelCustomizationUUID;
}
-
- /** serviceType */
- public String getServiceType() {
- return serviceType;
- }
- public void setServiceType(String serviceType) {
- this.serviceType= serviceType;
- }
- /** serviceRole */
- public String getServiceRole() {
- return serviceRole;
- }
- public void setServiceRole(String serviceRole) {
- this.serviceRole= serviceRole;
- }
- /** resourceVendorModelNumber */
- public String getResourceVendorModelNumber() {
- return resourceVendorModelNumber;
- }
- public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
- this.resourceVendorModelNumber= resourceVendorModelNumber;
- }
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java index c9e42f291..77fbe9135 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/beans/tosca/ToscaModel.java @@ -1,9 +1,9 @@ /*-
- * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -14,7 +14,7 @@ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
- * limitations under the License. + * limitations under the License.
* ============LICENSE_END=========================================================
*/
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/local/LocalAsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/local/LocalAsdcClient.java new file mode 100644 index 000000000..8538f6ba6 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/local/LocalAsdcClient.java @@ -0,0 +1,388 @@ +package org.openecomp.vid.asdc.local; + +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.json.JSONArray; +import org.json.JSONObject; +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.AsdcClient; +import org.openecomp.vid.asdc.beans.Artifact; +import org.openecomp.vid.asdc.beans.Resource; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.asdc.beans.tosca.ToscaCsar; +import org.openecomp.vid.asdc.beans.tosca.ToscaMeta; +import org.openecomp.vid.asdc.beans.tosca.ToscaModel; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.*; +import java.util.zip.ZipFile; + +/** + * The Class LocalAsdcClient. + */ +public class LocalAsdcClient implements AsdcClient { + + + /** + * The catalog. + */ + private final JSONObject catalog; + + /** + * The mapper. + */ + private final ObjectMapper mapper; + + /** + * The Class Builder. + */ + public static class Builder { + + /** + * The catalog. + */ + private JSONObject catalog = new JSONObject() + .put("resources", new JSONObject()) + .put("services", new JSONObject()); + + /** + * The mapper. + */ + private ObjectMapper mapper = new ObjectMapper(); + + /** + * Instantiates a new builder. + */ + public Builder() { + } + + /** + * Catalog. + * + * @param catalog the catalog + * @return the builder + */ + public org.openecomp.vid.asdc.local.LocalAsdcClient.Builder catalog(JSONObject catalog) { + this.catalog = catalog; + return this; + } + + /** + * Mapper. + * + * @param mapper the mapper + * @return the builder + */ + public org.openecomp.vid.asdc.local.LocalAsdcClient.Builder mapper(ObjectMapper mapper) { + this.mapper = mapper; + return this; + } + + /** + * Builds the. + * + * @return the in local sdc client + */ + public org.openecomp.vid.asdc.local.LocalAsdcClient build() { + return new org.openecomp.vid.asdc.local.LocalAsdcClient(this); + } + } + + /** + * Instantiates a new in local sdc client. + * + * @param builder the builder + */ + private LocalAsdcClient(org.openecomp.vid.asdc.local.LocalAsdcClient.Builder builder) { + catalog = builder.catalog; + mapper = builder.mapper; + } + + /** + * Gets the catalog. + * + * @return the catalog + */ + private JSONObject getCatalog() { + return catalog; + } + + /** + * Gets the mapper. + * + * @return the mapper + */ + private ObjectMapper getMapper() { + return mapper; + } + + /** + * Convert. + * + * @param <T> the generic type + * @param json the json + * @param clazz the clazz + * @return the t + * @throws AsdcCatalogException the sdc catalog exception + */ + private <T> T convert(JSONObject json, Class<T> clazz) throws AsdcCatalogException { + try { + return getMapper().readValue(json.toString(), clazz); + } catch (JsonParseException e) { + throw new AsdcCatalogException("Failed to parse SDC response (bad data)", e); + } catch (JsonMappingException e) { + throw new AsdcCatalogException("Failed to map SDC response to internal VID data structure(s)", e); + } catch (IOException e) { + throw new AsdcCatalogException("Failed to get a response from SDC", e); + } + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getResource(java.util.UUID) + */ + public Resource getResource(UUID uuid) throws AsdcCatalogException { + final JSONObject resource = getCatalog().getJSONObject("resources") + .getJSONObject(uuid.toString()); + return convert(resource, Resource.class); + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getResources() + */ + public Collection<Resource> getResources() throws AsdcCatalogException { + final Collection<Resource> resources = new LinkedList<Resource>(); + + for (String key : getCatalog().getJSONObject("resources").keySet()) { + final JSONObject json = getCatalog().getJSONObject("resources").getJSONObject(key); + final Resource resource = convert(json, Resource.class); + resources.add(resource); + } + + return resources; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getResources(java.util.Map) + */ + public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException { + final Collection<Resource> resources = new LinkedList<Resource>(); + + for (String key : getCatalog().getJSONObject("resources").keySet()) { + final JSONObject json = getCatalog().getJSONObject("resources").getJSONObject(key); + + boolean filterMatch = true; + + for (Map.Entry<String, String[]> entry : filter.entrySet()) { + for (int i = 0; i < entry.getValue().length; i++) { + if (!json.getString(entry.getKey()).equals(entry.getValue()[i])) { + filterMatch = false; + break; + } + } + } + + if (filterMatch) resources.add(convert(json, Resource.class)); + } + + return resources; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID) + */ + public Service getService(UUID uuid) throws AsdcCatalogException { + + JSONObject serviceJsonObject = null; + final JSONArray categoryJsonArray = getCatalog().getJSONArray("services"); + + for (int i = 0; i < categoryJsonArray.length() ; i++) { + JSONObject jsonServiceObject = categoryJsonArray.getJSONObject(i); + if (jsonServiceObject.get("uuid").equals(uuid.toString())) { + serviceJsonObject = jsonServiceObject; + break; + } + } + + if (serviceJsonObject != null) + return convert(serviceJsonObject, Service.class); + else return null; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getServices() + */ + public Collection<Service> getServices() throws AsdcCatalogException { + final Collection<Service> services = new LinkedList<Service>(); + + JSONArray servicesArr = getCatalog().getJSONArray("services"); + + for (Object objService : servicesArr) { + JSONObject jsonServiceItem = (JSONObject) objService; + final Service service = convert(jsonServiceItem, Service.class); + services.add(service); + } + + return services; + } + + /* (non-Javadoc) + * @see org.openecompt.vid.asdc.AsdcClient#getServices(java.util.Map) + */ + public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException { + final Collection<Service> services = new LinkedList<Service>(); + + JSONArray catalogServices = catalog.getJSONArray("services"); + + for (int i = 0; i < catalogServices.length(); i++) { + + JSONObject serviceJson = catalogServices.getJSONObject(i); + + boolean filterMatch = true; + + for (Map.Entry<String, String[]> entry : filter.entrySet()) { + for (int j = 0; j < entry.getValue().length; j++) { + if (!serviceJson.getString(entry.getKey()).equals(entry.getValue()[j])) { + filterMatch = false; + break; + } + } + } + if (filterMatch) services.add(convert(serviceJson, Service.class)); + } + return services; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID) + */ + public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException { + final JSONArray artifacts = getCatalog().getJSONObject("resources") + .getJSONObject(resourceUuid.toString()) + .getJSONArray("artifacts"); + + for (int i = 0; i < artifacts.length(); i++) { + final JSONObject artifact = artifacts.getJSONObject(i); + + if (artifact.getString("artifactUUID").equals(artifactUuid.toString())) { + return convert(artifact, Artifact.class); + } + } + + return null; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID) + */ + public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException { + final JSONArray artifacts = getCatalog().getJSONObject("services") + .getJSONObject(serviceUuid.toString()) + .getJSONArray("artifacts"); + + for (int i = 0; i < artifacts.length(); i++) { + final JSONObject artifact = artifacts.getJSONObject(i); + + if (artifact.getString("artifactUUID").equals(artifactUuid.toString())) { + return convert(artifact, Artifact.class); + } + } + + return null; + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID) + */ + public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException { + final String toscaModelURL = getCatalog().getJSONObject("resources") + .getJSONObject(resourceUuid.toString()) + .getString("toscaModelURL"); + + + final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); + + if (toscaModelStream == null) return null; + + return null;//getToscaModel(toscaModelStream); + } + + /* (non-Javadoc) + * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) + */ + public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { + + String toscaModelURL = null; + + final JSONArray categoryJsonArray = getCatalog().getJSONArray("services"); + + for (int i = 0; i < categoryJsonArray.length() ; i++) { + + JSONObject jsonServiceObject = categoryJsonArray.getJSONObject(i); + if (jsonServiceObject.get("uuid").equals(serviceUuid.toString())) { + toscaModelURL = jsonServiceObject.getString("toscaModelURL"); + } + } + + final InputStream toscaModelStream = getClass().getClassLoader().getResourceAsStream(toscaModelURL); + + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource(toscaModelURL).getFile()); + Path path = Paths.get(file.getPath()); + + if (toscaModelStream == null) return null; + + return path; + } + + /** + * Gets the tosca model. + * + * @param csarInputStream the csar input stream + * @return the tosca model + * @throws AsdcCatalogException the asdc catalog exception + */ + private ToscaCsar getToscaModel(InputStream csarInputStream) throws AsdcCatalogException { + final Path csarFile; + + try { + csarFile = Files.createTempFile("csar", ".zip"); + Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + throw new AsdcCatalogException("Caught IOException while creating CSAR", e); + } + + try (final ZipFile csar = new ZipFile(csarFile.toFile())) { + + final InputStream toscaMetaStream = csar.getInputStream(csar.getEntry("TOSCA-Metadata/TOSCA.meta")); + final ToscaMeta toscaMeta = new ToscaMeta.Builder(toscaMetaStream).build(); + final String entryDefinitions = toscaMeta.get("Entry-Definitions"); + final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions)); + + final Yaml yaml = new Yaml(); + final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class); + + final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel); + + for (Map<String, Map<String, String>> imports : parentModel.getImports()) { + for (Map.Entry<String, Map<String, String>> entry : imports.entrySet()) { + final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + entry.getValue().get("file"))); + final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); + csarBuilder.addVnf(childModel); + } + } + + return csarBuilder.build(); + } catch (IOException e) { + throw new AsdcCatalogException("Caught IOException while processing CSAR", e); + } + } + +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java index c5134bfca..123cc5788 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/memory/InMemoryAsdcClient.java @@ -7,7 +7,7 @@ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@@ -168,7 +168,6 @@ public class InMemoryAsdcClient implements AsdcClient { }
/* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getResources()
*/
public Collection<Resource> getResources() throws AsdcCatalogException {
final Collection<Resource> resources = new LinkedList<Resource> ();
@@ -299,7 +298,7 @@ public class InMemoryAsdcClient implements AsdcClient { /* (non-Javadoc)
* @see org.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID)
*/
- public ToscaCsar getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {
+ public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {
final String toscaModelURL = getCatalog().getJSONObject("resources")
.getJSONObject(resourceUuid.toString())
.getString("toscaModelURL");
@@ -309,13 +308,13 @@ public class InMemoryAsdcClient implements AsdcClient { if (toscaModelStream == null) return null;
- return getToscaModel(toscaModelStream);
+ return null;//getToscaModel(toscaModelStream);
}
/* (non-Javadoc)
* @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID)
*/
- public ToscaCsar getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {
+ public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {
final String toscaModelURL = getCatalog().getJSONObject("services")
.getJSONObject(serviceUuid.toString())
.getString("toscaModelURL");
@@ -324,7 +323,7 @@ public class InMemoryAsdcClient implements AsdcClient { if (toscaModelStream == null) return null;
- return getToscaModel(toscaModelStream);
+ return null;//getToscaModel(toscaModelStream);
}
/**
@@ -369,4 +368,5 @@ public class InMemoryAsdcClient implements AsdcClient { throw new AsdcCatalogException("Caught IOException while processing CSAR", e);
}
}
+
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParser.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParser.java new file mode 100644 index 000000000..eb1669846 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParser.java @@ -0,0 +1,15 @@ +package org.openecomp.vid.asdc.parser; + +import java.nio.file.Path; + +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.beans.tosca.ToscaCsar; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.model.ServiceModel; + +public interface ToscaParser{ + ToscaCsar parse(Path path) throws AsdcCatalogException; + + ServiceModel makeServiceModel(String uuid,Path path,Service asdcServiceMetadata) throws Exception; +}
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl.java new file mode 100644 index 000000000..bea5da877 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl.java @@ -0,0 +1,225 @@ +package org.openecomp.vid.asdc.parser; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.Map.Entry; +import java.util.zip.ZipFile; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.asdc.beans.tosca.NodeTemplate; +import org.openecomp.vid.asdc.beans.tosca.ToscaCsar; +import org.openecomp.vid.asdc.beans.tosca.ToscaMeta; +import org.openecomp.vid.asdc.beans.tosca.ToscaModel; +import org.openecomp.vid.model.ModelConstants; +import org.openecomp.vid.model.Network; +import org.openecomp.vid.model.Node; +import org.openecomp.vid.model.ServiceModel; +import org.openecomp.vid.model.VNF; +import org.openecomp.vid.properties.VidProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; + +public class ToscaParserImpl implements ToscaParser { + /** The Constant LOG. */ + static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ToscaParserImpl.class); + + @Autowired + private final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + + private static final String asdcModelNamespace = VidProperties.getAsdcModelNamespace(); + private static final String vnfTag = asdcModelNamespace + ModelConstants.VNF; + private static final String networkTag = asdcModelNamespace + ModelConstants.NETWORK; + private static final String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE; + + + @Override + public ToscaCsar parse(Path path) throws AsdcCatalogException { + return getToscaCsar(path); + } + + private ToscaCsar getToscaCsar(final Path csarFile) throws AsdcCatalogException { + try (final ZipFile csar = new ZipFile(csarFile.toFile())) { + + final InputStream toscaMetaStream = csar.getInputStream(csar.getEntry("TOSCA-Metadata/TOSCA.meta")); + final ToscaMeta toscaMeta = new ToscaMeta.Builder(toscaMetaStream).build(); + final String entryDefinitions = toscaMeta.get("Entry-Definitions"); + final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions)); + + try { + final Yaml yaml = new Yaml(); + final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class); + + final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel); + + for (Map<String, Map<String, String>> imports : parentModel.getImports()) { + LOG.debug("imports = " + imports.toString()); + for (Entry<String, Map<String, String>> entry : imports.entrySet()) { + if (entry.getValue() != null) { + String fname = entry.getValue().get("file"); + if ((fname != null) && (fname.startsWith("service") || fname.startsWith("resource"))) { + LOG.debug("fname = " + fname); + final InputStream toscaChildEntryYamlStream = csar + .getInputStream(csar.getEntry("Definitions/" + fname)); + + final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); + csarBuilder.addVnf(childModel); + } + } + } + } + + return csarBuilder.build(); + } catch (YAMLException e) { + throw new AsdcCatalogException("Caught exception while processing TOSCA YAML", e); + } + } catch (IOException e) { + throw new AsdcCatalogException("Caught IOException while processing CSAR", e); + } + } + + public ServiceModel makeServiceModel(String uuid, final Path serviceCsar,Service service ) throws AsdcCatalogException, SdcToscaParserException { + + + final ServiceModel serviceModel = new ServiceModel(); + ToscaCsar toscaCsar = getToscaCsar(serviceCsar); + String methodName = "getServices"; + LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); + Boolean isNewFlow = false; + final Map<String, VNF> vnfs = new HashMap<String, VNF>(); + final Map<String, Network> networks = new HashMap<String, Network>(); + final ToscaModel asdcServiceToscaModel = toscaCsar.getParent(); + serviceModel.setService(ServiceModel.extractService(asdcServiceToscaModel, service)); + + + populateVnfsAndNetwork(methodName, isNewFlow, vnfs, networks, asdcServiceToscaModel, serviceModel); + + // If we see customization uuid under vnf or network, follow 1702 flow + if (isNewFlow) { + return (getCustomizedServices(asdcServiceToscaModel, serviceModel)); + } else { + VNF vnf = null; + for (ToscaModel vnfModel : toscaCsar.getChildren()) { + // using uuid to match should only be valid for 1610 models + final String vnfUuid = (vnfModel.getMetadata().getUUID()); + // find the VNF with that uuid, uuid is not the key anymore + vnf = findVNFAccordingToUUID(vnfs, vnfUuid); + if (vnf == null) { + LOG.warn("Couldn't find VNF object " + vnfUuid + ". Problem with Tosca model?"); + continue; + } + extractAndUpdateInputs(vnf, vnfModel); + ServiceModel.extractGroups(vnfModel, serviceModel); + } + + serviceModel.setVnfs(vnfs); + serviceModel.setNetworks(networks); + return serviceModel; + } + } + + private VNF findVNFAccordingToUUID(final Map<String, VNF> vnfs, final String vnfUuid) { + VNF vnf = null; + for (Entry<String, VNF> vnfComp : vnfs.entrySet()) { + if (((vnfComp.getValue().getUuid()).equalsIgnoreCase(vnfUuid))) { + // found the vnf + vnf = vnfComp.getValue(); + } + } + return vnf; + } + + private void extractAndUpdateInputs(VNF vnf, ToscaModel vnfModel) { + vnf.setInputs(vnfModel.gettopology_template().getInputs()); + } + + private static void populateVnfsAndNetwork(String methodName, Boolean isNewFlow, final Map<String, VNF> vnfs, + final Map<String, Network> networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) + throws AsdcCatalogException, SdcToscaParserException { + for (Entry<String, NodeTemplate> component : extractNodeTemplates(asdcServiceToscaModel)) { + final String modelCustomizationName = component.getKey(); + LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + + " model customization name: " + modelCustomizationName); + final NodeTemplate nodeTemplate = component.getValue(); + final String type = nodeTemplate.getType(); + + if (type.startsWith(vnfTag)) { + LOG.debug(EELFLoggerDelegate.debugLogger, + dateFormat.format(new Date()) + methodName + " found node template type: " + type); + final VNF vnf = new VNF(); + vnf.extractVnf(modelCustomizationName, nodeTemplate); +// populateNodeVersionIfMissing(nodeTemplate, vnf,service); + LOG.debug(EELFLoggerDelegate.debugLogger, + dateFormat.format(new Date()) + methodName + " VNF commands: " + vnf.getCommands()); + vnfs.put(modelCustomizationName, vnf); + isNewFlow = isNewFlow(vnf); + } + // Networks + if (type.startsWith(networkTag)) { + LOG.debug(EELFLoggerDelegate.debugLogger, + dateFormat.format(new Date()) + methodName + " found node template type: " + type); + final Network network = new Network(); + network.extractNetwork(modelCustomizationName, nodeTemplate); +// populateNodeVersionIfMissing(nodeTemplate, network, service); + isNewFlow = isNewFlow(network); + networks.put(modelCustomizationName, network); + + } + } + serviceModel.setVnfs(vnfs); + serviceModel.setNetworks(networks); + + } + + private static Set<Entry<String, NodeTemplate>> extractNodeTemplates(final ToscaModel asdcServiceToscaModel) { + return asdcServiceToscaModel.gettopology_template().getnode_templates().entrySet(); + } + + private static boolean isNewFlow(Node node) { + return (node.getCustomizationUuid() != null) && (node.getCustomizationUuid().length() > 0); + } + + private static boolean isNodeVersionMissing(Node Node) { + return Node.getVersion() == null; + } + + private static void populateNodeVersionIfMissing(final NodeTemplate nodeTemplate, final Node node, Service service) + throws AsdcCatalogException { + if (isNodeVersionMissing(node)) { + node.setVersion(service.getVersion()); + } + } + + private ServiceModel getCustomizedServices(ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) { + String methodName = "asdcServiceToscaModel"; + LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); + + // asdcServiceToscaModel should have vf modules and vol groups populated + // at this point but + // they are not associated with the VNFs + ServiceModel.extractGroups(asdcServiceToscaModel,serviceModel); + // Now put the vf modules and volume groups under the VNF they belong + // too + serviceModel.associateGroups(); + return (serviceModel); + } + + + private UUID extractUUIDFromNodeTemplate(final NodeTemplate nodeTemplate) { + return UUID.fromString(nodeTemplate.getMetadata().getUUID()); + } + + +}
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl2.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl2.java new file mode 100644 index 000000000..4819cae8f --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/parser/ToscaParserImpl2.java @@ -0,0 +1,226 @@ +package org.openecomp.vid.asdc.parser; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.tosca.parser.impl.FilterType; +import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.Property; +import org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint; +import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.model.*; + +import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ToscaParserImpl2 { + + + public class Constants { + public final static String uuid = "UUID"; + public final static String description = "description"; + public final static String ecompGeneratedNaming = "ecompGeneratedNaming"; + public final static String customizationUUID = "customizationUUID"; + public final static String vfModuleModelVersion = "vfModuleModelVersion"; + public final static String vfModuleModelCustomizationUUID = "vfModuleModelCustomizationUUID"; + public final static String volume_group = "volume_group"; + public final static String vfModuleModelInvariantUUID = "vfModuleModelInvariantUUID"; + public final static String vfModuleModelUUID = "vfModuleModelUUID"; + public final static String invariantUUID = "invariantUUID"; + public final static String version = "version"; + public final static String name = "name"; + public final static String category = "category"; + public final static String vfModuleModelName = "vfModuleModelName"; + public final static String getInput = "get_input"; + } + + public ToscaParserImpl2() { + + } + + public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws Exception { + ServiceModel serviceModel = new ServiceModel(); + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath()); + serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper)); + serviceModel.setVolumeGroups(extractVolumeGroups(sdcCsarHelper)); + serviceModel.setVfModules(extractVfModuleFromCsar(sdcCsarHelper)); + serviceModel.setVnfs(extractVnfsFromCsar(sdcCsarHelper)); + serviceModel.setNetworks(extractNetworksFromCsar(sdcCsarHelper)); + return serviceModel; + } + + private org.openecomp.vid.model.Service extractServiceFromCsar(Service asdcServiceMetadata, ISdcCsarHelper csarHelper) throws SdcToscaParserException { + org.openecomp.vid.model.Service service = new org.openecomp.vid.model.Service(); + + service.setName(csarHelper.getServiceMetadata().getValue(Constants.name)); + service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.category)); + service.setInvariantUuid(csarHelper.getServiceMetadata().getValue(Constants.invariantUUID)); + service.setUuid(csarHelper.getServiceMetadata().getValue(Constants.uuid)); + service.setVersion(asdcServiceMetadata.getVersion()); + service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.description)); + service.setInputs(inputsListToInputsMap(csarHelper.getServiceInputs())); + service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ecompGeneratedNaming)); + return service; + } + + private Map<String, VNF> extractVnfsFromCsar(ISdcCsarHelper csarHelper) { + List<NodeTemplate> nodeTemplates = csarHelper.getServiceVfList(); + Map<String, VNF> vnfsMaps = new HashMap<String, VNF>(); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + VNF vnf = new VNF(); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf); + vnf.setModelCustomizationName(nodeTemplate.getName()); + vnfsMaps.put(nodeTemplate.getName(), vnf); + } + return vnfsMaps; + } + + private Map<String, Network> extractNetworksFromCsar(ISdcCsarHelper csarHelper) { + List<NodeTemplate> nodeTemplates = csarHelper.getServiceVlList(); + Map<String, Network> networksMap = new HashMap<String, Network>(); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + Network newNetwork = new Network(); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, newNetwork); + newNetwork.setModelCustomizationName(nodeTemplate.getName()); + networksMap.put(nodeTemplate.getName(), newNetwork); + } + return networksMap; + } + + private Map<String, VfModule> extractVfModuleFromCsar(ISdcCsarHelper csarHelper) { + List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList(); + HashMap<String, VfModule> vfModuleHashMap = new HashMap<>(); + + for (NodeTemplate nodeTemplate : serviceVfList) { + List<Group> groups = csarHelper.getVfModulesByVf(nodeTemplate.getMetaData().getValue(Constants.customizationUUID)); + for (Group group : groups) { + vfModuleHashMap.put(group.getName(), populateVfModuleFromGroup(group)); + } + } + return vfModuleHashMap; + } + + + private Map<String, VolumeGroup> extractVolumeGroups(ISdcCsarHelper csarHelper) { + HashMap<String, VolumeGroup> volumeGroupHashMap = new HashMap<>(); + for (NodeTemplate nodeTemplate : csarHelper.getServiceVfList()) { + List<Group> groups = csarHelper.getVfModulesByVf(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + for (Group group : groups) { + boolean isVolumeGroup = Boolean.valueOf(group.getPropertyValue(Constants.volume_group).toString()); + if (isVolumeGroup) { + volumeGroupHashMap.put(group.getName(), populateVolumeGroupFromGroup(group)); + } + } + } + return volumeGroupHashMap; + } + + private Map<String, org.openecomp.vid.asdc.beans.tosca.Input> inputsListToInputsMap(List<org.openecomp.sdc.toscaparser.api.parameters.Input> inputList) { + Map<String, org.openecomp.vid.asdc.beans.tosca.Input> inputs = new HashMap<>(); + for (org.openecomp.sdc.toscaparser.api.parameters.Input input : inputList) { + inputs.put(input.getName(), convertInput(input, new org.openecomp.vid.asdc.beans.tosca.Input())); + } + return inputs; + } + + private Node populateNodeFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode) { + newNode.setCustomizationUuid(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.description)); + newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.invariantUUID)); + newNode.setUuid(nodeTemplate.getMetaData().getValue(Constants.uuid)); + newNode.setName(nodeTemplate.getMetaData().getValue(Constants.name)); + newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.version)); + newNode.setInputs(extractInputsAndCommandsForNodeTemplate(nodeTemplate, csarHelper, newNode)); + Map<String, String> propertiesMap = setPropertiesOfVnf(nodeTemplate.getPropertiesObjects()); + newNode.setProperties(propertiesMap); + return newNode; + } + + private VfModule populateVfModuleFromGroup(Group group){ + VfModule vfModule = new VfModule(); + + vfModule.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion)); + vfModule.setCustomizationUuid(group.getMetadata().getValue(Constants.vfModuleModelCustomizationUUID)); + vfModule.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName)); + vfModule.setName(group.getMetadata().getValue(Constants.vfModuleModelName)); + vfModule.setVolumeGroupAllowed(Boolean.valueOf((group.getPropertyValue(Constants.volume_group)).toString())); + vfModule.setDescription(group.getDescription()); + vfModule.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID)); + vfModule.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID)); + return vfModule; + } + + private VolumeGroup populateVolumeGroupFromGroup(Group group){ + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setDescription(group.getDescription()); + volumeGroup.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID)); + volumeGroup.setName(group.getMetadata().getValue(Constants.vfModuleModelName)); + volumeGroup.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName)); + volumeGroup.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion)); + volumeGroup.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID)); + return volumeGroup; + } + + + private Map<String, org.openecomp.vid.asdc.beans.tosca.Input> extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode){ + Map<String, org.openecomp.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>(); + Map<String, CommandProperty> commandPropertyMap = new HashMap<>(); + + List<Input> inputs = csarHelper.getServiceInputs(); + Map<String, String> properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.getInput); + for (Map.Entry<String, String> property : properties.entrySet()) { + String inputKey = property.getValue(); + String key = extractInputValue(inputKey); + for (Input input: inputs){ + if(input.getName().equals(key)){ + org.openecomp.vid.asdc.beans.tosca.Input localInput = new org.openecomp.vid.asdc.beans.tosca.Input(); + localInput = convertInput(input, localInput); + String name = property.getKey(); + commandPropertyMap.put(name, extractCommands(name, key)); + inputMap.put(name, localInput); + } + } + } + newNode.setCommands(commandPropertyMap); + return inputMap; + } + + private String extractInputValue(String inputKey) { + return inputKey.substring(inputKey.indexOf(":") + 1); + } + + private org.openecomp.vid.asdc.beans.tosca.Input convertInput(Input parserInput, org.openecomp.vid.asdc.beans.tosca.Input localInput){ + localInput.setDefault(parserInput.getDefault()); + localInput.setDescription(parserInput.getDescription()); + localInput.setRequired(parserInput.isRequired()); + localInput.setType(parserInput.getType()); + localInput.setConstraints(parserInput.getConstraints()); +// localInput.setentry_schema() + return localInput; + } + + private CommandProperty extractCommands(String displayName, String inputName){ + CommandProperty commandProperty = new CommandProperty(); + commandProperty.setDisplayName(displayName); + commandProperty.setCommand(Constants.getInput); + commandProperty.setInputName(inputName); + return commandProperty; + } + + private Map<String, String> setPropertiesOfVnf(List<Property> properties) { + Map<String, String> propertiesMap = new HashMap<String, String>(); + for (Property property : properties) { + propertiesMap.put(property.getName(), property.getValue().toString()); + } + return propertiesMap; + } + + +}
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java b/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java index 9f7c3a57d..5b783f5cd 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/asdc/rest/RestfulAsdcClient.java @@ -20,10 +20,28 @@ package org.openecomp.vid.asdc.rest;
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.vid.asdc.AsdcCatalogException;
+import org.openecomp.vid.asdc.AsdcClient;
+import org.openecomp.vid.asdc.beans.Artifact;
+import org.openecomp.vid.asdc.beans.Resource;
+import org.openecomp.vid.asdc.beans.Service;
+import org.openecomp.vid.asdc.parser.ToscaParserImpl;
+import org.openecomp.vid.model.ModelConstants;
+import org.openecomp.vid.properties.VidProperties;
+
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ResponseProcessingException;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedHashMap;
import java.io.IOException;
import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.File;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -35,441 +53,413 @@ import java.util.Collections; import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
-import java.util.zip.ZipFile;
-
-import javax.ws.rs.NotFoundException;
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ResponseProcessingException;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedHashMap;
-
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.openecomp.vid.asdc.AsdcCatalogException;
-import org.openecomp.vid.asdc.AsdcClient;
-import org.openecomp.vid.asdc.beans.Artifact;
-import org.openecomp.vid.asdc.beans.Resource;
-import org.openecomp.vid.asdc.beans.Service;
-import org.openecomp.vid.asdc.beans.tosca.ToscaCsar;
-import org.openecomp.vid.asdc.beans.tosca.ToscaMeta;
-import org.openecomp.vid.asdc.beans.tosca.ToscaModel;
-import org.openecomp.vid.model.ModelConstants;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.error.YAMLException;
-
-import org.openecomp.vid.properties.VidProperties;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
/**
* The Class RestfulAsdcClient.
*/
public class RestfulAsdcClient implements AsdcClient {
- /** The Constant LOG. */
- private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RestfulAsdcClient.class);
-
- /** The Constant dateFormat. */
- final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
-
- /** The client. */
- private final Client client;
-
- /** The uri. */
- private final URI uri;
-
- /** The common headers. */
- private final MultivaluedHashMap<String, Object> commonHeaders;
-
- /** The auth. */
- private final String auth;
-
- /**
- * The Class Builder.
- */
- public static class Builder {
-
- /** The client. */
- private final Client client;
-
- /** The uri. */
- private final URI uri;
-
- /** The auth. */
- private String auth = null;
-
- /**
- * Instantiates a new builder.
- *
- * @param client the client
- * @param uri the uri
- */
- public Builder(Client client, URI uri) {
- this.client = client;
- this.client.register(JacksonJsonProvider.class);
- this.uri = uri;
- }
-
- /**
- * Auth.
- *
- * @param auth the auth
- * @return the builder
- */
- public Builder auth(String auth) {
- this.auth = auth;
- return this;
- }
-
- /**
- * Builds the.
- *
- * @return the restful asdc client
- */
- public RestfulAsdcClient build() {
- return new RestfulAsdcClient(this);
- }
- }
-
- /**
- * Instantiates a new restful asdc client.
- *
- * @param builder the builder
- */
- private RestfulAsdcClient(Builder builder) {
- client = builder.client;
- uri = builder.uri;
- auth = builder.auth;
-
- commonHeaders = new MultivaluedHashMap<String, Object> ();
- commonHeaders.put("X-ECOMP-InstanceID", Collections.singletonList((Object) "VID"));
- commonHeaders.put("Authorization", Collections.singletonList((Object) (auth)));
- }
-
- /**
- * Gets the client.
- *
- * @return the client
- */
- private Client getClient() { return client; }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getResource(java.util.UUID)
- */
- public Resource getResource(UUID uuid) throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path + "/" + uuid.toString() + "/metadata")
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .get(Resource.class);
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getResources()
- */
- public Collection<Resource> getResources() throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path)
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .get(new GenericType<Collection<Resource>> () {});
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getResources(java.util.Map)
- */
- public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- WebTarget target = getClient()
- .target(uri)
- .path(path);
-
- for (Entry<String, String[]> filterEntry : filter.entrySet()) {
- target = target.queryParam(filterEntry.getKey(), (Object []) filterEntry.getValue());
- }
-
- try {
- return target.request()
- .accept(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .get(new GenericType<Collection<Resource>> () {});
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (NotFoundException e) {
- throw e;
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID)
- */
- public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path + "/" + resourceUuid + "/artifacts/" + artifactUuid)
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .get(Artifact.class);
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID)
- */
- public Service getService(UUID uuid) throws AsdcCatalogException {
-
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path( path + "/" + uuid.toString() + "/metadata")
- .request(MediaType.APPLICATION_JSON)
- .headers(commonHeaders)
- .get(Service.class);
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getServices()
- */
- public Collection<Service> getServices() throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path)
- .request()
- .accept(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .get(new GenericType<Collection<Service>> () {});
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getServices(java.util.Map)
- */
- public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException {
-
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- WebTarget target = getClient()
- .target(uri)
- .path(path);
-
-
- for (Entry<String, String[]> filterEntry : filter.entrySet()) {
- target = target.queryParam(filterEntry.getKey(), (Object []) filterEntry.getValue());
- }
-
- try {
- return target.request()
- .accept(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .get(new GenericType<Collection<Service>> () {});
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (NotFoundException e) {
- throw e;
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID)
- */
- public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- return getClient()
- .target(uri)
- .path(path + "/" + serviceUuid + "/artifacts/" + artifactUuid)
- .request(MediaType.APPLICATION_JSON_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .get(Artifact.class);
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID)
- */
- public ToscaCsar getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
- try (final InputStream csarInputStream = (InputStream) getClient()
- .target(uri)
- .path(path + "/" + resourceUuid + "/toscaModel")
- .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
- .get(InputStream.class)) {
-
- return getToscaModel(csarInputStream);
- } catch (IOException e) {
- throw new AsdcCatalogException("Failed to retrieve resource TOSCA model from ASDC", e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID)
- */
- public ToscaCsar getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {
- String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try {
- final InputStream csarInputStream = (InputStream) getClient()
- .target(uri)
- .path(path + "/" + serviceUuid + "/toscaModel")
- .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
- .headers(commonHeaders)
- .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
- .get(InputStream.class);
-
- return getToscaModel(csarInputStream);
- } catch (ResponseProcessingException e) {
- //Couldn't convert response to Java type
- throw new AsdcCatalogException("ASDC response could not be processed", e);
- } catch (ProcessingException e) {
- //IO problems during request
- throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
- } catch (WebApplicationException e) {
- //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
- throw new AsdcCatalogException(e);
- }
- }
-
- /**
- * Gets the tosca model.
- *
- * @param csarInputStream the csar input stream
- * @return the tosca model
- * @throws AsdcCatalogException the asdc catalog exception
- */
- private ToscaCsar getToscaModel(InputStream csarInputStream) throws AsdcCatalogException {
- final Path csarFile;
- try {
- csarFile = Files.createTempFile("csar", ".zip");
- Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING);
- } catch (IOException e) {
- throw new AsdcCatalogException("Caught IOException while creating CSAR", e);
- }
+ /**
+ * The Class Builder.
+ */
+ public static class Builder {
+
+ /**
+ * The client.
+ */
+ private final Client client;
+
+ /**
+ * The uri.
+ */
+ private final URI uri;
+
+ /**
+ * The auth.
+ */
+ private String auth = null;
+
+ /**
+ * Instantiates a new builder.
+ *
+ * @param client the client
+ * @param uri the uri
+ */
+ public Builder(Client client, URI uri) {
+ this.client = client;
+ this.client.register(JacksonJsonProvider.class);
+ this.uri = uri;
+ }
+
+ /**
+ * Auth.
+ *
+ * @param auth the auth
+ * @return the builder
+ */
+ public Builder auth(String auth) {
+ this.auth = auth;
+ return this;
+ }
+
+ /**
+ * Builds the.
+ *
+ * @return the restful asdc client
+ */
+ public RestfulAsdcClient build() {
+ return new RestfulAsdcClient(this);
+ }
+ }
+
+ /**
+ * The Constant LOG.
+ */
+ static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RestfulAsdcClient.class);
+
+ /**
+ * The Constant dateFormat.
+ */
+ final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+
+ /**
+ * The client.
+ */
+ private final Client client;
+
+ /**
+ * The uri.
+ */
+ private final URI uri;
+
+ /**
+ * The common headers.
+ */
+ private final MultivaluedHashMap<String, Object> commonHeaders;
+
+ /**
+ * The auth.
+ */
+ private final String auth;
+
+ ToscaParserImpl p = new ToscaParserImpl();
+
+ /**
+ * Instantiates a new restful asdc client.
+ *
+ * @param builder the builder
+ */
+ private RestfulAsdcClient(Builder builder) {
+ client = builder.client;
+ uri = builder.uri;
+ auth = builder.auth;
+
+ commonHeaders = new MultivaluedHashMap<String, Object>();
+ commonHeaders.put("X-ECOMP-InstanceID", Collections.singletonList((Object) "VID"));
+ commonHeaders.put("Authorization", Collections.singletonList((Object) (auth)));
+ }
+
+ private Path createTmpFile(InputStream csarInputStream) throws AsdcCatalogException {
+ final Path csarFile;
+ try {
+ csarFile = Files.createTempFile("csar", ".zip");
+ Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e) {
+ throw new AsdcCatalogException("Caught IOException while creating CSAR", e);
+ }
+ return csarFile;
+ }
+
+ /**
+ * Gets the client.
+ *
+ * @return the client
+ */
+ private Client getClient() {
+ return client;
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getResource(java.util.UUID)
+ */
+ public Resource getResource(UUID uuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + uuid.toString() + "/metadata")
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .get(Resource.class);
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID)
+ */
+ public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + resourceUuid + "/artifacts/" + artifactUuid)
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .get(Artifact.class);
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getResources()
+ */
+ public Collection<Resource> getResources() throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path)
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .get(new GenericType<Collection<Resource>>() {
+ });
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getResources(java.util.Map)
+ */
+ public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ WebTarget target = getClient()
+ .target(uri)
+ .path(path);
+
+ for (Entry<String, String[]> filterEntry : filter.entrySet()) {
+ target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue());
+ }
+
+ try {
+ return target.request()
+ .accept(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .get(new GenericType<Collection<Resource>>() {
+ });
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (NotFoundException e) {
+ throw e;
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID)
+ */
+ public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);
+ try (final InputStream csarInputStream = (InputStream) getClient()
+ .target(uri)
+ .path(path + "/" + resourceUuid + "/toscaModel")
+ .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
+ .get(InputStream.class)) {
+
+ return getToscaCsar(csarInputStream);
+ } catch (IOException e) {
+ throw new AsdcCatalogException("Failed to retrieve resource TOSCA model from ASDC", e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID)
+ */
+ public Service getService(UUID uuid) throws AsdcCatalogException {
+
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + uuid.toString() + "/metadata")
+ .request(MediaType.APPLICATION_JSON)
+ .headers(commonHeaders)
+ .get(Service.class);
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID)
+ */
+ public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
- try (final ZipFile csar = new ZipFile(csarFile.toFile())) {
-
- final InputStream toscaMetaStream = csar.getInputStream(csar.getEntry("TOSCA-Metadata/TOSCA.meta"));
- final ToscaMeta toscaMeta = new ToscaMeta.Builder(toscaMetaStream).build();
- final String entryDefinitions = toscaMeta.get("Entry-Definitions");
- final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions));
-
- try {
- final Yaml yaml = new Yaml();
- final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class);
-
- final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel);
-
- for (Map<String, Map<String, String>> imports : parentModel.getImports()) {
- LOG.debug("imports = " + imports.toString());
- for (Entry<String, Map<String, String>> entry : imports.entrySet()) {
- if ( entry.getValue() != null) {
- String fname = entry.getValue().get("file");
- if ( ( fname != null ) && (fname.startsWith("service") || fname.startsWith("resource")) ) {
- LOG.debug("fname = " + fname);
- final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + fname ));
- final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class);
- csarBuilder.addVnf(childModel);
- }
- }
- }
- }
-
- return csarBuilder.build();
- } catch (YAMLException e) {
- throw new AsdcCatalogException("Caught exception while processing TOSCA YAML", e);
- }
- } catch (IOException e) {
- throw new AsdcCatalogException("Caught IOException while processing CSAR", e);
- }
- }
+ try {
+ return getClient()
+ .target(uri)
+ .path(path + "/" + serviceUuid + "/artifacts/" + artifactUuid)
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .get(Artifact.class);
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getServices()
+ */
+ public Collection<Service> getServices() throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ try {
+ return getClient()
+ .target(uri)
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .get(new GenericType<Collection<Service>>() {
+ });
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getServices(java.util.Map)
+ */
+ public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException {
+
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ WebTarget target = getClient()
+ .target(uri)
+ .path(path);
+
+
+ for (Entry<String, String[]> filterEntry : filter.entrySet()) {
+ target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue());
+ }
+
+ try {
+ return target.request()
+ .accept(MediaType.APPLICATION_JSON_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .get(new GenericType<Collection<Service>>() {
+ });
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (NotFoundException e) {
+ throw e;
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID)
+ */
+ public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {
+ String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);
+ try {
+ final InputStream csarInputStream = (InputStream) getClient()
+ .target(uri)
+ .path(path + "/" + serviceUuid + "/toscaModel")
+ .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
+ .headers(commonHeaders)
+ .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)
+ .get(InputStream.class);
+
+
+ return getToscaCsar(csarInputStream);
+ } catch (ResponseProcessingException e) {
+ //Couldn't convert response to Java type
+ throw new AsdcCatalogException("ASDC response could not be processed", e);
+ } catch (ProcessingException e) {
+ //IO problems during request
+ throw new AsdcCatalogException("Failed to get a response from ASDC service", e);
+ } catch (WebApplicationException e) {
+ //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)
+ throw new AsdcCatalogException(e);
+ }
+ }
+
+
+ /**
+ * Gets the tosca model.
+ *
+ * @param csarInputStream the csar input stream
+ * @return the tosca model
+ * @throws AsdcCatalogException the asdc catalog exception
+ */
+ private Path getToscaCsar(InputStream csarInputStream) throws AsdcCatalogException {
+ return createTmpFile(csarInputStream);
+ }
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java index 92b752859..861ddf8da 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java @@ -302,7 +302,6 @@ public class AaiController extends RestrictedBaseController{ * @param namedQueryId the named query id
* @param globalCustomerId the global customer id
* @param serviceType the service type
- * @param serviceInstance the service instance
* @return ResponseEntity The response entity
*/
@RequestMapping(value="/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET)
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java b/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java index f7bf3a54e..9972ae5d3 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java @@ -20,144 +20,39 @@ package org.openecomp.vid.controller;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.UUID;
-
-import javax.net.ssl.SSLContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Client;
-
-import org.json.JSONObject;
-import org.json.JSONTokener;
+import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.vid.asdc.AsdcCatalogException;
import org.openecomp.vid.exceptions.VidServiceUnavailableException;
-import org.openecomp.vid.model.ModelUtil;
-import org.openecomp.vid.model.ModelConstants;
-import org.openecomp.vid.model.Network;
import org.openecomp.vid.model.ServiceModel;
-import org.openecomp.vid.model.VNF;
-import org.openecomp.vid.model.VfModule;
-import org.openecomp.vid.model.VolumeGroup;
-//import org.openecomp.vid.model.Service;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
+import org.openecomp.vid.services.*;
-import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.openecomp.vid.asdc.AsdcCatalogException;
-import org.openecomp.vid.asdc.AsdcClient;
-import org.openecomp.vid.asdc.beans.Resource;
-import org.openecomp.vid.asdc.beans.Service;
-import org.openecomp.vid.asdc.beans.tosca.Group;
-import org.openecomp.vid.asdc.beans.tosca.NodeTemplate;
-import org.openecomp.vid.asdc.beans.tosca.ToscaCsar;
-import org.openecomp.vid.asdc.beans.tosca.ToscaModel;
-import org.openecomp.vid.asdc.memory.InMemoryAsdcClient;
-import org.openecomp.vid.asdc.rest.RestfulAsdcClient;
-import org.openecomp.vid.properties.AsdcClientConfiguration;
-import org.openecomp.vid.properties.AsdcClientConfiguration.AsdcClientType;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.openecomp.vid.properties.VidProperties;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+import java.util.Map;
+
+//import org.openecomp.vid.model.Service;
-/**
- * The Class VidController.
- */
@RestController
public class VidController extends RestrictedBaseController {
- /** The Constant LOG. */
private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class);
-
- /** The Constant dateFormat. */
- final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
-
- /** The app context. */
- @Autowired
- private ApplicationContext appContext;
-
- /**
- * Gets the object mapper.
- *
- * @return the object mapper
- */
- @Bean
- public ObjectMapper getObjectMapper() {
- return new ObjectMapper();
- }
-
- /**
- * Gets the asdc client.
- *
- * @return the asdc client
- */
- @Bean
- public AsdcClient getAsdcClient() {
-
- final AsdcClientConfiguration asdcClientConfig = appContext.getBean(AsdcClientConfiguration.class);
- switch (asdcClientConfig.getAsdcClientType()) {
- case IN_MEMORY:
- final InputStream asdcCatalogFile = VidController.class.getClassLoader().getResourceAsStream("catalog.json");
- final JSONTokener tokener = new JSONTokener(asdcCatalogFile);
- final JSONObject catalog = new JSONObject(tokener);
+ private final VidService service;
- return new InMemoryAsdcClient.Builder().catalog(catalog).build();
- case REST:
+ @Autowired
+ public VidController(VidService vidService) throws SdcToscaParserException{
- final String protocol = asdcClientConfig.getAsdcClientProtocol();
- final String host = asdcClientConfig.getAsdcClientHost();
- final int port = asdcClientConfig.getAsdcClientPort();
- final String auth = asdcClientConfig.getAsdcClientAuth();
- Client cl = null;
- if ( protocol.equalsIgnoreCase("https") ) {
- try {
- SSLContext ctx = SSLContext.getInstance("TLSv1.2");
- ctx.init(null, null, null);
- cl = ClientBuilder.newBuilder().sslContext(ctx).build();
- }
- catch ( NoSuchAlgorithmException n ) {
- throw new RuntimeException("SDC Client could not be instantiated due to unsupported protocol TLSv1.2", n);
- }
- catch ( KeyManagementException k ) {
- throw new RuntimeException("SDC Client could not be instantiated due to a key management exception", k);
- }
- }
- else {
- cl = ClientBuilder.newBuilder().build();
- }
-
- try {
- final URI uri = new URI(protocol + "://" + host + ":" + port + "/");
- return new RestfulAsdcClient.Builder(cl, uri)
- .auth(auth)
- .build();
- } catch (URISyntaxException e) {
- throw new RuntimeException("SDC Client could not be instantiated due to a syntax error in the URI", e);
- }
-
- default:
- throw new RuntimeException(asdcClientConfig.getAsdcClientType() + " is invalid; must be one of " + Arrays.toString(AsdcClientType.values()));
- }
+ service = vidService;
}
-
+//
/**
* Gets the services.
*
@@ -168,7 +63,8 @@ public class VidController extends RestrictedBaseController { @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET)
public Collection<org.openecomp.vid.asdc.beans.Service> getServices(HttpServletRequest request) throws VidServiceUnavailableException {
try {
- return getAsdcClient().getServices(request.getParameterMap());
+ Map<String, String[]> requestParams = request.getParameterMap();
+ return service.getServices(requestParams);
} catch (AsdcCatalogException e) {
LOG.error("Failed to retrieve service definitions from SDC", e);
throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
@@ -188,159 +84,14 @@ public class VidController extends RestrictedBaseController { */
@RequestMapping(value={"/rest/models/services/{uuid}"}, method = RequestMethod.GET)
public ServiceModel getServices(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException {
- String methodName = "getServices";
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
- boolean isNewFlow = false;
-
- String asdcModelNamespaces[] = VidProperties.getAsdcModelNamespace();
- String[] vnfTags = ModelUtil.getTags(asdcModelNamespaces, ModelConstants.VNF);
- String[] networkTags = ModelUtil.getTags(asdcModelNamespaces, ModelConstants.NETWORK);
- String[] vfModuleTags = ModelUtil.getTags(asdcModelNamespaces, ModelConstants.VF_MODULE);
-
try {
- final ServiceModel serviceModel = new ServiceModel();
- final Map<String, VNF> vnfs = new HashMap<String, VNF> ();
- final Map<String, Network> networks = new HashMap<String, Network> ();
-
- final ToscaCsar serviceCsar = getAsdcClient().getServiceToscaModel(UUID.fromString(uuid));
- final Service asdcServiceMetadata = getAsdcClient().getService(UUID.fromString(uuid));
- final ToscaModel asdcServiceToscaModel = serviceCsar.getParent();
-
- serviceModel.setService(ServiceModel.extractService(asdcServiceToscaModel, asdcServiceMetadata));
-
- for (Entry<String, NodeTemplate> component: asdcServiceToscaModel.gettopology_template().getnode_templates().entrySet()) {
- final String modelCustomizationName = component.getKey();
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " model customization name: " + modelCustomizationName);
- final NodeTemplate nodeTemplate = component.getValue();
- final String type = nodeTemplate.getType();
-
- // is it a VNF?
- if ( ModelUtil.isType (type, vnfTags) ) {
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " found node template type: " + type);
-
- final UUID vnfUuid = UUID.fromString(nodeTemplate.getMetadata().getUUID());
- final VNF vnf = new VNF();
- vnf.extractVnf(modelCustomizationName, nodeTemplate);
-
- if (vnf.getVersion() == null) {
- // vnf version should always be populated. The call below may not return the correct metadata since
- // uuid is not unique
- final Resource vnfMetadata = getAsdcClient().getResource(UUID.fromString(nodeTemplate.getMetadata().getUUID()));
- vnf.setVersion(vnfMetadata.getVersion());
- }
-
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " VNF commands: " + vnf.getCommands());
- vnfs.put(modelCustomizationName, vnf);
- if ( (vnf.getCustomizationUuid() != null) && (vnf.getCustomizationUuid().length() > 0 ) ) {
- isNewFlow = true;
- }
- }
-
- // is it a Network?
- if ( ModelUtil.isType (type, networkTags) ) {
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " found node template type: " + type);
- final UUID networkUuid = UUID.fromString(nodeTemplate.getMetadata().getUUID());
- final Network network = new Network();
- network.extractNetwork(modelCustomizationName, nodeTemplate);
-
- if (network.getVersion() == null) {
- // network version should always be populated. The call below may not return the correct metadata since
- // uuid is not unique
- final Resource networkMetadata = getAsdcClient().getResource(UUID.fromString(nodeTemplate.getMetadata().getUUID()));
- network.setVersion(networkMetadata.getVersion());
- }
- if ( (network.getCustomizationUuid() != null) && (network.getCustomizationUuid().length() > 0 ) ) {
- isNewFlow = true;
- }
- networks.put(modelCustomizationName, network);
-
- }
- }
- serviceModel.setVnfs(vnfs);
- serviceModel.setNetworks(networks);
- // If we see customization uuid under vnf or network, follow 1702 flow
- if ( isNewFlow ) {
- return ( getCustomizedServices(asdcServiceToscaModel, serviceModel) );
- }
- VNF vnf = null;
- for (ToscaModel vnfModel : serviceCsar.getChildren()) {
-
- // using uuid to match should only be valid for 1610 models
-
- final String vnfUuid = (vnfModel.getMetadata().getUUID());
- // find the VNF with that uuid, uuid is not the key anymore
- for ( Entry<String, VNF> vnfComp : vnfs.entrySet() ) {
- if ( ( ( vnfComp.getValue().getUuid() ).equalsIgnoreCase(vnfUuid) ) ) {
- // found the vnf
- vnf = vnfComp.getValue();
- }
- }
- final Map<String, VfModule> vfModules = new HashMap<String, VfModule> ();
- final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
-
- if (vnf == null) {
- LOG.warn("Couldn't find VNF object " + vnfUuid + ". Problem with Tosca model?");
- continue;
- }
-
- vnf.setInputs(vnfModel.gettopology_template().getInputs());
-
- for (Entry<String, Group> component1 : vnfModel.gettopology_template().getGroups().entrySet()) {
- final Group group = component1.getValue();
- final String type = group.getType();
- final String modelCustomizationName = component1.getKey();
-
- // VF Module Customization UUID: We may have the complete set of all VF Modules for all VNFs under service and VF Modules under each VNF.
- // Keep using the VF Modules under VNFs but we need to get the customization uuid from the service level and put them
- // under each VF module at the VNF level
- if ( ModelUtil.isType (type, vfModuleTags) ) {
-
- VfModule vfMod = VfModule.extractVfModule(modelCustomizationName, group);
-
- // Add the vf module customization uuid from the service model
- // The key of the VF Module in the service level will be the VF instance name appended to the VF Module name:
- // <VF instance name>..<VF Module name>
- /* String normalizedVnfCustomizationName = VNF.normalizeName (vnf.getModelCustomizationName());
- org.openecomp.vid.model.Service.extractVfModuleCustomizationUUID (serviceModel.getService(), normalizedVnfCustomizationName, vfMod);*/
-
- vfModules.put(modelCustomizationName, vfMod);
-
- if ( vfMod.isVolumeGroupAllowed() ) {
- volumeGroups.put(modelCustomizationName, VolumeGroup.extractVolumeGroup(modelCustomizationName, group));
- }
-
- }
- }
-
- vnf.setVfModules(vfModules);
- vnf.setVolumeGroups(volumeGroups);
- }
-
- serviceModel.setVnfs(vnfs);
- serviceModel.setNetworks(networks);
-
- return serviceModel;
+ return service.getService(uuid);
} catch (AsdcCatalogException e) {
LOG.error("Failed to retrieve service definitions from SDC", e);
throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
}
- catch (Exception e) {
- LOG.error("Failed to retrieve service definitions from SDC", e);
- throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
- }
}
- public ServiceModel getCustomizedServices(ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) {
- String methodName = "asdcServiceToscaModel";
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
-
- // asdcServiceToscaModel should have vf modules and vol groups populated at this point but
- // they are not associated with the VNFs
- serviceModel.extractGroups(asdcServiceToscaModel);
- // Now put the vf modules and volume groups under the VNF they belong too
- serviceModel.associateGroups();
- return (serviceModel);
- }
/**
* Gets the services view.
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java new file mode 100644 index 000000000..9a258a109 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java @@ -0,0 +1,106 @@ +package org.openecomp.vid.controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.openecomp.vid.asdc.AsdcClient; +import org.openecomp.vid.asdc.local.LocalAsdcClient; +import org.openecomp.vid.asdc.memory.InMemoryAsdcClient; +import org.openecomp.vid.asdc.rest.RestfulAsdcClient; +import org.openecomp.vid.asdc.parser.ToscaParserImpl2; +import org.openecomp.vid.properties.AsdcClientConfiguration; +import org.openecomp.vid.properties.AsdcClientConfiguration.AsdcClientType; +import org.openecomp.vid.services.VidService; +import org.openecomp.vid.services.VidServiceImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.net.ssl.SSLContext; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +@Configuration +public class WebConfig { + + /** + * Gets the object mapper. + * + * @return the object mapper + */ + @Bean + public ObjectMapper getObjectMapper() { + return new ObjectMapper(); + } + + @Bean + public VidService vidService(AsdcClient asdcClient) { + return new VidServiceImpl(asdcClient); + } + + @Bean + public AsdcClient asdcClient(AsdcClientConfiguration asdcClientConfig) throws IOException { + switch (asdcClientConfig.getAsdcClientType()) { + case IN_MEMORY: + final InputStream asdcCatalogFile = VidController.class.getClassLoader().getResourceAsStream("catalog.json"); + final JSONTokener tokener = new JSONTokener(asdcCatalogFile); + final JSONObject catalog = new JSONObject(tokener); + + return new InMemoryAsdcClient.Builder().catalog(catalog).build(); + case REST: + + final String protocol = asdcClientConfig.getAsdcClientProtocol(); + final String host = asdcClientConfig.getAsdcClientHost(); + final int port = asdcClientConfig.getAsdcClientPort(); + final String auth = asdcClientConfig.getAsdcClientAuth(); + Client cl = null; + if (protocol.equalsIgnoreCase("https")) { + try { + SSLContext ctx = SSLContext.getInstance("TLSv1.2"); + ctx.init(null, null, null); + cl = ClientBuilder.newBuilder().sslContext(ctx).build(); + } catch (NoSuchAlgorithmException n) { + throw new RuntimeException("SDC Client could not be instantiated due to unsupported protocol TLSv1.2", n); + } catch (KeyManagementException k) { + throw new RuntimeException("SDC Client could not be instantiated due to a key management exception", k); + } + } else { + cl = ClientBuilder.newBuilder().build(); + } + + try { + final URI uri = new URI(protocol + "://" + host + ":" + port + "/"); + return new RestfulAsdcClient.Builder(cl, uri) + .auth(auth) + .build(); + } catch (URISyntaxException e) { + throw new RuntimeException("SDC Client could not be instantiated due to a syntax error in the URI", e); + } + + case LOCAL: + + final InputStream asdcServicesFile = VidController.class.getClassLoader().getResourceAsStream("sdcservices.json"); + + final JSONTokener jsonTokener = new JSONTokener(IOUtils.toString(asdcServicesFile)); + final JSONObject sdcServicesCatalog = new JSONObject(jsonTokener); + + return new LocalAsdcClient.Builder().catalog(sdcServicesCatalog).build(); + + default: + throw new RuntimeException(asdcClientConfig.getAsdcClientType() + " is invalid; must be one of " + Arrays.toString(AsdcClientType.values())); + } + } + + @Bean + public ToscaParserImpl2 getToscaParser() { + return new ToscaParserImpl2(); + } + +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/ModelUtil.java b/vid-app-common/src/main/java/org/openecomp/vid/model/ModelUtil.java deleted file mode 100755 index 4606aa021..000000000 --- a/vid-app-common/src/main/java/org/openecomp/vid/model/ModelUtil.java +++ /dev/null @@ -1,61 +0,0 @@ -/*-
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.vid.model;
-
-/**
- * The Class ModelUtil.
- *
- */
-public class ModelUtil {
- /**
- * Gets the tags for the given element according to the configured namespace
- * @param namespaces the namespace list from the configuration
- * @param constantValue the constant portion of the tag name, i.e. resource.vf...
- * @return the tags
- */
- public static String[] getTags ( String[] namespaces, String constantValue ) {
- String[] tags;
- if ( namespaces == null || namespaces.length == 0 ) {
- return null;
- }
- int le = namespaces.length;
- tags = new String[le];
- for ( int i = 0; i < le; i++ ) {
- tags[i] = namespaces[i] + constantValue;
- }
- return (tags);
- }
- /**
- * Determine if a note template type matches a set of configurable tags
- * @param type the node template type
- * @param tags the model configurable namespaces
- * @return true if type starts with a tag in the array, false otherwise
- */
- public static boolean isType ( String type, String[] tags ) {
- if ( (tags != null) && (tags.length > 0) ) {
- for ( int i = 0; i < tags.length; i++ ) {
- if ( type.startsWith (tags[i]) ) {
- return (true);
- }
- }
- }
- return (false);
- }
-}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/Network.java b/vid-app-common/src/main/java/org/openecomp/vid/model/Network.java index 5ab55881b..e763496fc 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/model/Network.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/Network.java @@ -49,7 +49,7 @@ public class Network extends Node { *
* @param modelCustomizationName the new model customization name
*/
- private void setModelCustomizationName(String modelCustomizationName) {
+ public void setModelCustomizationName(String modelCustomizationName) {
this.modelCustomizationName = modelCustomizationName;
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/NewNetwork.java b/vid-app-common/src/main/java/org/openecomp/vid/model/NewNetwork.java new file mode 100644 index 000000000..48e3a55fd --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/NewNetwork.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.model; + +import org.openecomp.vid.asdc.beans.tosca.NodeTemplate; + +/** + * The Class Network. + */ +public class NewNetwork extends NewNode { + + /** The model customization name. */ + private String modelCustomizationName; + + /** + * Instantiates a new network. + */ + public NewNetwork() { + super(); + } + /** + * Gets the model customization name. + * + * @return the model customization name + */ + public String getModelCustomizationName() { + return modelCustomizationName; + } + /** + * Sets the model customization name. + * + * @param modelCustomizationName the new model customization name + */ + public void setModelCustomizationName(String modelCustomizationName) { + this.modelCustomizationName = modelCustomizationName; + } + +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/NewNode.java b/vid-app-common/src/main/java/org/openecomp/vid/model/NewNode.java new file mode 100644 index 000000000..681131fc9 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/NewNode.java @@ -0,0 +1,209 @@ +package org.openecomp.vid.model; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.vid.asdc.beans.tosca.Input; + + +public class NewNode { + + /** The Constant LOG. */ + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(Node.class); + + /** The Constant dateFormat. */ + final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + /** The uuid. */ + private String uuid; + + /** The invariant uuid. */ + private String invariantUuid; + + /** The description. */ + private String description; + + /** The name. */ + private String name; + + /** The version. */ + private String version; + + /** The model customization uuid. */ + private String customizationUuid; + + /** The inputs. */ + private Map<String, Input> inputs; + + /** The get_input or other constructs from node template properties. */ + private Map<String, CommandProperty> commands; + + /** The get_input or other constructs from node template properties. */ + private Map<String, String> properties; + /** + * Instantiates a new node. + */ + public NewNode() { + this.commands = new HashMap<String, CommandProperty>(); + this.properties = new HashMap<String, String>(); + } + + /** + * Gets the uuid. + * + * @return the uuid + */ + public String getUuid() { + return uuid; + } + + /** + * Gets the invariant uuid. + * + * @return the invariant uuid + */ + public String getInvariantUuid() { + return invariantUuid; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Gets the customization uuid. + * + * @return the model customization uuid + */ + public String getCustomizationUuid() { + return customizationUuid; + } + /** + * Gets the inputs. + * + * @return the inputs + */ + public Map<String, Input> getInputs() { + return inputs; + } + /** + * Gets the commands. + * + * @return the commands + */ + public Map<String, CommandProperty> getCommands() { + return commands; + } + /** + * Gets the properties. + * + * @return the properties + */ + public Map<String, String> getProperties() { + return properties; + } + /** + * Sets the uuid. + * + * @param uuid the new uuid + */ + public void setUuid(String uuid) { + this.uuid = uuid; + } + + /** + * Sets the invariant uuid. + * + * @param invariantUuid the new invariant uuid + */ + public void setInvariantUuid(String invariantUuid) { + this.invariantUuid = invariantUuid; + } + + /** + * Sets the description. + * + * @param description the new description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Sets the version. + * + * @param version the new version + */ + public void setVersion(String version) { + this.version = version; + } + /** + * Sets the customization uuid. + * + * @param u the new customization uuid + */ + public void setCustomizationUuid(String u) { + this.customizationUuid = u; + } + + /** + * Sets the inputs. + * + * @param inputs the inputs + */ + public void setInputs(Map<String, Input> inputs) { + this.inputs = inputs; + } + /** + * Sets the commands. + * + * @param m the commands + */ + public void setCommands( Map<String, CommandProperty>m ) { + commands = m; + } + /** + * Sets the properties. + * + * @param p the properties + */ + public void setProperties( Map<String, String>p) { + properties = p; + } + +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/NewService.java b/vid-app-common/src/main/java/org/openecomp/vid/model/NewService.java new file mode 100644 index 000000000..1dcf0224e --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/NewService.java @@ -0,0 +1,252 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.model; + +import java.util.Map; +import java.util.UUID; + +import org.openecomp.vid.asdc.beans.tosca.Input; + +/** + * The Class Service. + */ +public class NewService { + + /** The uuid. */ + private String uuid; + + /** The invariant uuid. */ + private String invariantUuid; + + /** The name. */ + private String name; + + /** The version. */ + private String version; + + /** The tosca model URL. */ + private String toscaModelURL; + + /** The category. */ + private String category; + + /** The description. */ + private String description; + + /** The service ecomp naming flag */ + private String serviceEcompNaming; + + /** The inputs. */ + private Map<String, Input> inputs; + + /** + * Gets the uuid. + * + * @return the uuid + */ + public String getUuid() { + return uuid; + } + + /** + * Gets the invariant uuid. + * + * @return the invariant uuid + */ + public String getInvariantUuid() { + return invariantUuid; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Gets the tosca model URL. + * + * @return the tosca model URL + */ + public String getToscaModelURL() { + return toscaModelURL; + } + + /** + * Gets the category. + * + * @return the category + */ + public String getCategory() { + return category; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Gets the inputs. + * + * @return the inputs + */ + public Map<String, Input> getInputs() { + return inputs; + } + /** + * Get the serviceEcompNaming value + * + * @return serviceEcompNaming + */ + public String getServiceEcompNaming() { + return serviceEcompNaming; + } + /** + * Sets the uuid. + * + * @param uuid the new uuid + */ + public void setUuid(String uuid) { + this.uuid = uuid; + } + + /** + * Sets the invariant uuid. + * + * @param invariantUuid the new invariant uuid + */ + public void setInvariantUuid(String invariantUuid) { + this.invariantUuid = invariantUuid; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Sets the version. + * + * @param version the new version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Sets the tosca model URL. + * + * @param toscaModelURL the new tosca model URL + */ + public void setToscaModelURL(String toscaModelURL) { + this.toscaModelURL = toscaModelURL; + } + + /** + * Sets the category. + * + * @param category the new category + */ + public void setCategory(String category) { + this.category = category; + } + + /** + * Sets the description. + * + * @param description the new description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Sets the inputs. + * + * @param inputs the inputs + */ + public void setInputs(Map<String, Input> inputs) { + this.inputs = inputs; + } + /** + * Sets the service ecomp naming. + * + * @param serviceEcompNaming the new service ecomp naming + */ + public void setServiceEcompNaming(String serviceEcompNaming) { + this.serviceEcompNaming = serviceEcompNaming; + } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final UUID uuid = UUID.fromString(getUuid()); + + return uuid.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof NewService)) return false; + + final NewService service = (NewService) o; + + return (service.getUuid().equals(getUuid())); + } + /*public static void extractVfModuleCustomizationUUID (Service s, String vnfCustomizationName, VfModule vfMod ) { + + //Look for vnfCustomizationName..vfModuleCustomizationName + String nameToFind = vnfCustomizationName + ".." + vfMod.getModelCustomizationName(); + for (Entry<UUID, VfModule> vfModuleComponent : s.getVfModules().entrySet()) { + VfModule xMod = vfModuleComponent.getValue(); + if ( (xMod.getModelCustomizationName() != null) && (xMod.getModelCustomizationName().equalsIgnoreCase(nameToFind)) ) { + vfMod.setCustomizationUuid( xMod.getCustomizationUuid()); + return; + } + } + }*/ +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/NewServiceModel.java b/vid-app-common/src/main/java/org/openecomp/vid/model/NewServiceModel.java new file mode 100644 index 000000000..6fda979c1 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/NewServiceModel.java @@ -0,0 +1,259 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.vid.model; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.openecomp.vid.asdc.beans.tosca.Group; +import org.openecomp.vid.asdc.beans.tosca.ToscaModel; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.vid.properties.VidProperties; +/** + * The Class ServiceModel. + */ +public class NewServiceModel { + + /** The Constant LOG. */ + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(NewServiceModel.class); + + /** The Constant dateFormat. */ + final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + /** The service. */ + private Service service; + + /** The vnfs. */ + private Map<String, VNF> vnfs; + + /** The networks. */ + private Map<String, Network> networks; + + /** + * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info + * that is not present in the VNF, like the vf module customization String + */ + private Map<String, VfModule> vfModules; + /** + * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level + * for newer models + */ + private Map<String, VolumeGroup> volumeGroups; + /** + * Instantiates a new service model. + */ + public NewServiceModel() {} + + /** + * Gets the service. + * + * @return the service + */ + public Service getService() { + return service; + } + + /** + * Gets the vnfs. + * + * @return the vnfs + */ + public Map<String, VNF> getVnfs() { + return vnfs; + } + + /** + * Gets the networks. + * + * @return the networks + */ + public Map<String, Network> getNetworks() { + return networks; + } + + /** + * Sets the service. + * + * @param service the new service + */ + public void setService(Service service) { + this.service = service; + } + + /** + * Sets the vnfs. + * + * @param vnfs the vnfs + */ + public void setVnfs(Map<String, VNF> vnfs) { + this.vnfs = vnfs; + } + + /** + * Sets the networks. + * + * @param networks the networks + */ + public void setNetworks(Map<String, Network> networks) { + this.networks = networks; + } + /** + * Gets the vf modules. + * + * @return the vf modules + */ + public Map<String, VfModule> getVfModules() { + return vfModules; + } + /** + * Gets the volume groups. + * + * @return the volume groups + */ + public Map<String, VolumeGroup> getVolumeGroups() { + return volumeGroups; + } + /** + * Sets the vf modules. + * + * @param vfModules the vf modules + */ + public void setVfModules(Map<String, VfModule> vfModules) { + this.vfModules = vfModules; + } + /** + * Sets the volume groups. + * + * @param volumeGroups the volume groups + */ + public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) { + this.volumeGroups = volumeGroups; + } + /** + * Extract service. + * + * @param serviceToscaModel the service tosca model + * @param asdcServiceMetadata the asdc service metadata + * @return the service + */ + public static Service extractService(ToscaModel serviceToscaModel, org.openecomp.vid.asdc.beans.Service asdcServiceMetadata) { + + final Service service = new Service(); + + service.setCategory(serviceToscaModel.getMetadata().getCategory()); + service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID()); + service.setName(serviceToscaModel.getMetadata().getName()); + service.setUuid(serviceToscaModel.getMetadata().getUUID()); + service.setDescription(serviceToscaModel.getMetadata().getDescription()); + service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming()); + service.setInputs(serviceToscaModel.gettopology_template().getInputs()); + //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702 + //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME + //service.setVersion(serviceToscaModel.getMetadata().getVersion()); + service.setVersion(asdcServiceMetadata.getVersion()); + + return service; + } + public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) { + // Get the groups. The groups may duplicate the groups that are in the VNF model and have + // additional data like the VF module customization String> + + final Map<String, VfModule> vfModules = new HashMap<String, VfModule> (); + final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> (); + + String asdcModelNamespace = VidProperties.getAsdcModelNamespace(); + String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE; + + for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) { + final Group group = component.getValue(); + final String type = group.getType(); + final String customizationName = component.getKey(); + + if (type.startsWith(vfModuleTag)) { + VfModule vfMod = VfModule.extractVfModule(customizationName, group); + vfModules.put(customizationName, vfMod); + if ( vfMod.isVolumeGroupAllowed() ) { + //volume groups have the same customization name as the vf module + volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group)); + } + } + } + // add this point vfModules and volume groups are disconnected from VNF + serviceModel.setVfModules (vfModules); + serviceModel.setVolumeGroups (volumeGroups); + + } + /** + * Populate the vf modules and volume groups that we may have under the service level under each VNF. + */ +// public void associateGroups() { +// String methodName = "associateGroups()"; +// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); +// // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts +// // with vnf + ".." +// String vnfCustomizationName = null; +// String normalizedVnfCustomizationName = null; +// String vfModuleCustomizationName = null; +// NewVNF tmpVnf = null; +// +// if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) { +// for (Entry<String, NewVNF> vnfComponent : getVnfs().entrySet()) { +// vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName(); +// normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName); +// +// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + +// " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName); +// +// // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName +// +// if (( getVfModules() != null ) && (!(getVfModules().isEmpty()))) { +// for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) { +// vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName(); +// +// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + +// " VF Module customizationName=" + vfModuleCustomizationName ); +// if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) { +// +// // this vf module belongs to the VNF +// tmpVnf = vnfComponent.getValue(); +// (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue()); +// +// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + +// " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName); +// +// // now find if this vf module has volume groups, if so, find the volume group with the same customization name and put it under the VNF +// if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) { +// if (( getVolumeGroups() != null ) && (!(getVolumeGroups().isEmpty()))) { +// if (getVolumeGroups().containsKey((vfModuleCustomizationName))) { +// (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName)); +// } +// } +// } +// } +// } +// } +// } +// } + +// } +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/NewVNF.java b/vid-app-common/src/main/java/org/openecomp/vid/model/NewVNF.java new file mode 100644 index 000000000..e84f963c5 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/NewVNF.java @@ -0,0 +1,123 @@ +package org.openecomp.vid.model; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.vid.asdc.beans.tosca.NodeTemplate; + +public class NewVNF extends NewNode { + + /** The Constant LOG. */ + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VNF.class); + + /** The Constant dateFormat. */ + final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + /** The pattern used to normalize VNF names */ + final static Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+"); + + /** The model customization name. */ + private String modelCustomizationName; + + /** The vf modules. */ + private Map<String, VfModule> vfModules = new HashMap<String, VfModule>(); + + /** The volume groups. */ + private Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup>(); + + /** + * Instantiates a newvnf. + */ + public NewVNF() { + super(); + } + + /** + * Gets the model customization name. + * + * @return the model customization name + */ + public String getModelCustomizationName() { + return modelCustomizationName; + } + + /** + * Gets the vf modules. + * + * @return the vf modules + */ + public Map<String, VfModule> getVfModules() { + return vfModules; + } + + /** + * Sets the vf modules. + * + * @param vfModules the vf modules + */ + public void setVfModules(Map<String, VfModule> vfModules) { + this.vfModules = vfModules; + } + + /** + * Gets the volume groups. + * + * @return the volume groups + */ + public Map<String, VolumeGroup> getVolumeGroups() { + return volumeGroups; + } + + /** + * Sets the volume groups. + * + * @param volumeGroups the volume groups + */ + public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) { + this.volumeGroups = volumeGroups; + } + + + /** + * Sets the model customization name. + * + * @param modelCustomizationName the new model customization name + */ + public void setModelCustomizationName(String modelCustomizationName) { + this.modelCustomizationName = modelCustomizationName; + } + /** + * Normalize the VNF name + * @param originalName + * @return the normalized name + */ + public static String normalizeName (String originalName) { + + String normalizedName = originalName.toLowerCase(); + normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" "); + String[] splitArr = null; + + try { + splitArr = normalizedName.split(" "); + } + catch (Exception ex ) { + return (normalizedName); + } + StringBuffer sb = new StringBuffer(); + if ( splitArr != null ) { + for (String splitElement : splitArr) { + sb.append(splitElement); + } + return (sb.toString()); + } + else { + return (normalizedName); + } + + } + +} diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/ServiceModel.java b/vid-app-common/src/main/java/org/openecomp/vid/model/ServiceModel.java index 98e65316b..8742931c6 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/model/ServiceModel.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/ServiceModel.java @@ -30,11 +30,11 @@ import java.util.Map.Entry; import org.openecomp.vid.asdc.beans.tosca.Group;
import org.openecomp.vid.asdc.beans.tosca.ToscaModel;
import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.openecomp.vid.controller.VidController;
import org.openecomp.vid.properties.VidProperties;
/**
* The Class ServiceModel.
*/
+@SuppressWarnings("ALL")
public class ServiceModel {
/** The Constant LOG. */
@@ -176,21 +176,22 @@ public class ServiceModel { return service;
}
- public void extractGroups (ToscaModel serviceToscaModel) {
+ public static void extractGroups (ToscaModel serviceToscaModel,ServiceModel serviceModel) {
// Get the groups. The groups may duplicate the groups that are in the VNF model and have
// additional data like the VF module customization String>
final Map<String, VfModule> vfModules = new HashMap<String, VfModule> ();
final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
- String asdcModelNamespaces[] = VidProperties.getAsdcModelNamespace();
- String[] vfModuleTags = ModelUtil.getTags(asdcModelNamespaces, ModelConstants.VF_MODULE);
-
+
+ String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
+ String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
+
for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
final Group group = component.getValue();
final String type = group.getType();
final String customizationName = component.getKey();
- if ( ModelUtil.isType (type, vfModuleTags) ) {
+ if (type.startsWith(vfModuleTag)) {
VfModule vfMod = VfModule.extractVfModule(customizationName, group);
vfModules.put(customizationName, vfMod);
if ( vfMod.isVolumeGroupAllowed() ) {
@@ -200,8 +201,8 @@ public class ServiceModel { }
}
// add this point vfModules and volume groups are disconnected from VNF
- this.setVfModules (vfModules);
- this.setVolumeGroups (volumeGroups);
+ serviceModel.setVfModules (vfModules);
+ serviceModel.setVolumeGroups (volumeGroups);
}
/**
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/VNF.java b/vid-app-common/src/main/java/org/openecomp/vid/model/VNF.java index be37c947b..62e101ef8 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/model/VNF.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/VNF.java @@ -130,7 +130,7 @@ public class VNF extends Node { *
* @param modelCustomizationName the new model customization name
*/
- private void setModelCustomizationName(String modelCustomizationName) {
+ public void setModelCustomizationName(String modelCustomizationName) {
this.modelCustomizationName = modelCustomizationName;
}
/**
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/VfModule.java b/vid-app-common/src/main/java/org/openecomp/vid/model/VfModule.java index 4a031a6c6..3f6f1da22 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/model/VfModule.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/VfModule.java @@ -207,7 +207,7 @@ public class VfModule { *
* @param volumeGroupAllowed the new volume group allowed
*/
- private void setVolumeGroupAllowed(boolean volumeGroupAllowed) {
+ public void setVolumeGroupAllowed(boolean volumeGroupAllowed) {
this.volumeGroupAllowed = volumeGroupAllowed;
}
/**
@@ -223,7 +223,7 @@ public class VfModule { *
* @param modelCustomizationName the new model customization name
*/
- private void setModelCustomizationName(String modelCustomizationName) {
+ public void setModelCustomizationName(String modelCustomizationName) {
this.modelCustomizationName = modelCustomizationName;
}
/**
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/model/VolumeGroup.java b/vid-app-common/src/main/java/org/openecomp/vid/model/VolumeGroup.java index ea8e151d6..d09ef9a33 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/model/VolumeGroup.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/model/VolumeGroup.java @@ -170,7 +170,7 @@ public class VolumeGroup { *
* @param u the new customization name
*/
- private void setModelCustomizationName(String u) {
+ public void setModelCustomizationName(String u) {
this.modelCustomizationName = u;
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/mso/MsoRestInterfaceIfc.java b/vid-app-common/src/main/java/org/openecomp/vid/mso/MsoRestInterfaceIfc.java index b0dc906be..1a6dbcccb 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/mso/MsoRestInterfaceIfc.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/mso/MsoRestInterfaceIfc.java @@ -70,7 +70,7 @@ public interface MsoRestInterfaceIfc { */
public <T> void Post(T t, RequestDetails r, String sourceID, String path, RestObject<T> restObject) throws Exception;
- /**
+ /***
* Log request.
*
* @param r the r
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/properties/AsdcClientConfiguration.java b/vid-app-common/src/main/java/org/openecomp/vid/properties/AsdcClientConfiguration.java index 6d5f9522c..232023b4e 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/properties/AsdcClientConfiguration.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/properties/AsdcClientConfiguration.java @@ -24,31 +24,36 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.PropertySources;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
/**
* The Class AsdcClientConfiguration.
*/
@Configuration
-@PropertySource(value="${container.classpath:}/WEB-INF/conf/asdc.properties")
+
+@PropertySources({
+ @PropertySource(value="asdc.properties", ignoreResourceNotFound = true),
+ @PropertySource(value="${container.classpath:}/WEB-INF/conf/asdc.properties", ignoreResourceNotFound = true)
+})
public class AsdcClientConfiguration {
-
- @Bean
- public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
- return new PropertySourcesPlaceholderConfigurer();
+
+ @Bean
+ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
+ return new PropertySourcesPlaceholderConfigurer();
}
@Value("${asdc.client.type}")
private AsdcClientType asdcClientType;
-
+
/** The asdc client host. */
@Value("${asdc.client.rest.host}")
private String asdcClientHost;
-
+
/** The asdc client port. */
@Value("${asdc.client.rest.port}")
private int asdcClientPort;
-
+
/** The asdc client auth. */
@Value("${asdc.client.rest.auth}")
public String asdcClientAuth;
@@ -56,7 +61,7 @@ public class AsdcClientConfiguration { /** The asdc client protocol. */
@Value("${asdc.client.rest.protocol}")
public String asdcClientProtocol;
-
+
/**
* Gets the asdc client type.
*
@@ -101,16 +106,19 @@ public class AsdcClientConfiguration { public String getAsdcClientProtocol() {
return asdcClientProtocol;
}
-
+
/**
* The Enum AsdcClientType.
*/
public enum AsdcClientType {
-
+
/** The in memory. */
IN_MEMORY,
-
+
/** The rest. */
- REST
+ REST,
+
+ /** The local. */
+ LOCAL
}
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/properties/VidProperties.java b/vid-app-common/src/main/java/org/openecomp/vid/properties/VidProperties.java index 38062df40..141b9b27c 100755 --- a/vid-app-common/src/main/java/org/openecomp/vid/properties/VidProperties.java +++ b/vid-app-common/src/main/java/org/openecomp/vid/properties/VidProperties.java @@ -53,27 +53,21 @@ public class VidProperties extends SystemProperties { *
* @return the property value or a default value
*/
- public static String[] getAsdcModelNamespace() {
+ public static String getAsdcModelNamespace() {
String methodName = "getAsdcModelNamespace ";
- String[] asdcModelNamespaces = null;
- String value = null;
+ String asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
try {
- value = SystemProperties.getProperty(ModelConstants.ASDC_MODEL_NAMESPACE);
- if ( value == null || value.isEmpty()) {
- asdcModelNamespaces = new String[1];
- asdcModelNamespaces[0] = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
+ asdcModelNamespace = SystemProperties.getProperty(ModelConstants.ASDC_MODEL_NAMESPACE);
+ if ( asdcModelNamespace == null || asdcModelNamespace.isEmpty()) {
+ asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
}
- else {
- asdcModelNamespaces = value.split(",");
- }
}
catch ( Exception e ) {
LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "
+ ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE);
- asdcModelNamespaces = new String[1];
- asdcModelNamespaces[0] = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
+ asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
}
- return (asdcModelNamespaces);
+ return (asdcModelNamespace);
}
/**
* Gets the specified property value. If the property is not defined, returns a default value.
@@ -96,5 +90,4 @@ public class VidProperties extends SystemProperties { }
return (propValue);
}
-
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/services/VidService.java b/vid-app-common/src/main/java/org/openecomp/vid/services/VidService.java new file mode 100644 index 000000000..4fb0ff160 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/services/VidService.java @@ -0,0 +1,17 @@ +package org.openecomp.vid.services; + +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.model.ServiceModel; + +import java.util.Collection; +import java.util.Map; + +public interface VidService { + + Collection<Service> getServices(Map<String, String[]> requestParams) + throws AsdcCatalogException; + + ServiceModel getService(String uuid) throws AsdcCatalogException; + +}
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/openecomp/vid/services/VidServiceImpl.java b/vid-app-common/src/main/java/org/openecomp/vid/services/VidServiceImpl.java new file mode 100644 index 000000000..9844842f8 --- /dev/null +++ b/vid-app-common/src/main/java/org/openecomp/vid/services/VidServiceImpl.java @@ -0,0 +1,79 @@ +package org.openecomp.vid.services; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.vid.asdc.AsdcCatalogException; +import org.openecomp.vid.asdc.AsdcClient; +import org.openecomp.vid.asdc.beans.Service; +import org.openecomp.vid.asdc.parser.ToscaParser; +import org.openecomp.vid.asdc.parser.ToscaParserImpl; +import org.openecomp.vid.asdc.parser.ToscaParserImpl2; +import org.openecomp.vid.model.ServiceModel; +import org.springframework.beans.factory.annotation.Autowired; + +import java.nio.file.Path; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Map; +import java.util.UUID; + +/** + * The Class VidController. + */ + +public class VidServiceImpl implements VidService { + /** + * The Constant LOG. + */ + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidServiceImpl.class); + /** + * The Constant dateFormat. + */ + private final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + protected final AsdcClient asdcClient; + @Autowired + private ToscaParserImpl2 toscaParser; + + public VidServiceImpl(AsdcClient asdcClient) { + this.asdcClient = asdcClient; + } + + /* + * (non-Javadoc) + * + * @see org.openecomp.vid.controller.VidService#getServices(java.util.Map) + */ + @Override + public Collection<Service> getServices(Map<String, String[]> requestParams) + throws AsdcCatalogException { + return asdcClient.getServices(requestParams); + } + + /* + * (non-Javadoc) + * + * @see org.openecomp.vid.controller.VidService#getService(java.lang.String) + */ + @Override + public ServiceModel getService(String uuid) throws AsdcCatalogException { + final Path serviceCsar = asdcClient.getServiceToscaModel(UUID.fromString(uuid)); + ToscaParser tosca = new ToscaParserImpl(); + serviceCsar.toFile().getAbsolutePath(); + ServiceModel serviceModel = null; + try { + final Service asdcServiceMetadata = asdcClient.getService(UUID.fromString(uuid)); + try { + serviceModel = toscaParser.makeServiceModel(serviceCsar, asdcServiceMetadata); + } + catch (SdcToscaParserException e){ + serviceModel = tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata); + } + } catch (Exception e) { + e.printStackTrace(); + } + return serviceModel; + } + + +}
\ No newline at end of file |