1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
@import '../../../../assets/styles/variables';
@ng2-shadow-gray: #f8f8f8;
@ng2-light-gray: #eaeaea;
@ng2-medium-gray: #d2d2d2;
@ng2-med-dark-gray: #999999;
@ng2-dark-gray: #5a5a5a;
@ng2-shadow-blue: #e6f6fb;
@ng2-bold-blue: #009fdb;
@ng2-success-green:#4ca90c;
@ng2-title-font-size:16px;
@ng2-text-font-size: 14px;
:host { display:block; height: 100%; }
/deep/ tabs {display:flex; flex-direction:column; height:100%; }
.properties-assignment-page {
height: 100%;
.main-content {
display:flex;
flex-direction:row;
height: 100%;
}
.left-column {
flex: 1 0 500px;
position: relative;
margin: 0 0 1em 0;
/deep/ .tabs {
width:25%;
text-align:center;
}
/deep/ .tab {
padding: 10px .5em;
&.active {
color:#009fdb;
border-color: #d2d2d2;
border-top: solid 4px #009fdb;
background-color: white;
padding-top:7px;
}
}
.header {
position:absolute;
top:0;
right:0;
min-width:200px;
}
.search-filter-container{
position: relative;
right: 164px;
}
.search-box {
border: 1px solid @ng2-medium-gray;
border-radius: 4px;
height: 32px;
margin: 0;
padding: 2px 20px 4px 10px;
outline: none;
font-style: italic;
color:@ng2-med-dark-gray;
margin-right:10px;
&::-moz-placeholder { color:@ng2-med-dark-gray;}
&::-webkit-input-placeholder{ color:@ng2-med-dark-gray;}
}
.search-icon {
background-position: -48px
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
/*-
* ============LICENSE_START=======================================================
* OPENECOMP - MSO
* ================================================================================
* 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.mso.apihandlerinfra;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import org.hibernate.Query;
import org.hibernate.Session;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.openecomp.mso.apihandler.common.ErrorNumbers;
import org.openecomp.mso.apihandler.common.ValidationException;
import org.openecomp.mso.apihandlerinfra.volumebeans.ActionType;
import org.openecomp.mso.apihandlerinfra.volumebeans.VolumeInputs;
import org.openecomp.mso.apihandlerinfra.volumebeans.ObjectFactory;
import org.openecomp.mso.apihandlerinfra.volumebeans.RequestInfo;
import org.openecomp.mso.apihandlerinfra.volumebeans.RequestStatusType;
import org.openecomp.mso.apihandlerinfra.volumebeans.VolumeRequest;
import org.openecomp.mso.db.HibernateUtils;
import org.openecomp.mso.logger.MsoLogger;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.properties.MsoJavaProperties;
import org.openecomp.mso.requestsdb.HibernateUtilsRequestsDb;
import org.openecomp.mso.requestsdb.InfraActiveRequests;
import org.openecomp.mso.requestsdb.RequestsDatabase;
public class VolumeMsoInfraRequest {
private String requestId;
private String requestXML;
private String requestUri;
private RequestInfo rinfo;
private VolumeInputs volumeInputs;
private String volumeParams;
private ActionType action;
private String errorMessage;
private String httpResponse;
private String responseBody;
private RequestStatusType status;
private long startTime;
private long progress = Constants.PROGRESS_REQUEST_RECEIVED;
protected HibernateUtils hibernateUtils = new HibernateUtilsRequestsDb ();
private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
private static final String NOT_PROVIDED = "not provided";
VolumeMsoInfraRequest (String requestId) {
this.requestId = requestId;
this.startTime = System.currentTimeMillis();
MsoLogger.setLogContext (requestId, null);
}
// Parse request XML
void parse (String reqXML, String version, MsoJavaProperties props) throws ValidationException {
msoLogger.debug ("Validating the request");
this.requestXML = reqXML;
VolumeRequest volumeReq = null;
boolean isWrongRootElement = false;
try {
JAXBContext jaxbContext = JAXBContext.newInstance (VolumeRequest.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller ();
InputSource inputSource = new InputSource (new StringReader (reqXML));
SAXSource source = new SAXSource (inputSource);
if (reqXML.contains ("volume-request") && !reqXML.contains("vnf-request")) {
volumeReq = jaxbUnmarshaller.unmarshal (source, VolumeRequest.class).getValue ();
} else {
isWrongRootElement = true;
}
} catch (Exception e) {
msoLogger.error (MessageEnum.APIH_VNFREQUEST_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception when parsing reqXML", e);
throw new ValidationException ("format for volume request");
}
if (isWrongRootElement) {
msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR_REASON, "root element is not correct", "", "", MsoLogger.ErrorCode.SchemaError, "root element <volume-request> expected");
throw new ValidationException ("root element <volume-request> expected");
}
if (volumeReq == null) {
throw new ValidationException ("volume-request");
}
this.rinfo = volumeReq.getRequestInfo ();
if (this.rinfo == null) {
throw new ValidationException ("request-info");
}
action = this.rinfo.getAction ();
if (action == null) {
throw new ValidationException ("action");
}
this.volumeInputs = volumeReq.getVolumeInputs ();
if (this.volumeInputs == null) {
throw new ValidationException ("volume-inputs");
}
// Verify that the elements correspond to the version
if (version.equals(Constants.SCHEMA_VERSION_V1)) {
if (this.volumeInputs.getBackoutOnFailure() != null || this.volumeInputs.getAicCloudRegion() != null ||
this.volumeInputs.getVfModuleModelName () != null || this.volumeInputs.getAsdcServiceModelVersion () != null ||
this.volumeInputs.getServiceInstanceId () != null || this.volumeInputs.getVnfId () != null) {
throw new ValidationException ("format for v1 version of volume request");
}
}
else if (version.equals(Constants.SCHEMA_VERSION_V2)) {
if (this.volumeInputs.getServiceType() != null || this.volumeInputs.getAicNodeClli() != null ||
this.volumeInputs.getServiceInstanceId () != null || this.volumeInputs.getVnfId () != null) {
throw new ValidationException ("format for v2 version of volume request");
}
}
else if (version.equals(Constants.SCHEMA_VERSION_V3)) {
if (this.volumeInputs.getServiceType() != null || this.volumeInputs.getAicNodeClli() != null) {
throw new ValidationException ("format for v3 version of volume request");
}
}
if (!InfraUtils.isActionAllowed (props, "volume", version, action.value ())) {
throw new ValidationException ("action allowable for version " + version + " of volume request");
}
switch (action) {
case UPDATE:
case DELETE:
case UPDATE_VF_MODULE_VOL:
case DELETE_VF_MODULE_VOL:
if (this.volumeInputs.getVolumeGroupId () == null) {
throw new ValidationException ("volume-group-id");
}
break;
default:
break;
}
if (ActionType.CREATE.equals (action) || ActionType.CREATE_VF_MODULE_VOL.equals(action)) {
if (this.volumeInputs.getVolumeGroupName () == null) {
throw new ValidationException ("volume-group-name");
}
if (!InfraUtils.isValidHeatName(this.volumeInputs.getVolumeGroupName ())) {
throw new ValidationException ("volume-group-name: no value meeting heat stack name syntax requirements");
}
}
if (this.volumeInputs.getVnfType () == null) {
throw new ValidationException ("vnf-type");
}
switch (action) {
case CREATE_VF_MODULE_VOL:
case UPDATE_VF_MODULE_VOL:
case DELETE_VF_MODULE_VOL:
if (this.volumeInputs.getVfModuleModelName () == null) {
throw new ValidationException ("vf-module-model-name");
}
break;
default:
break;
}
if (!version.equals(Constants.SCHEMA_VERSION_V1) && this.volumeInputs.getServiceId () == null) {
throw new ValidationException ("service-id ");
}
if (version.equals(Constants.SCHEMA_VERSION_V1) && this.volumeInputs.getServiceType () != null && this.volumeInputs.getServiceId () != null) {
throw new ValidationException ("service-type or service-id ");
}
if (version.equals(Constants.SCHEMA_VERSION_V1) && this.volumeInputs.getAicNodeClli () == null) {
throw new ValidationException ("aic-node-clli");
}
if ((version.equals(Constants.SCHEMA_VERSION_V2) || version.equals(Constants.SCHEMA_VERSION_V3)) && (this.volumeInputs.getAicCloudRegion () == null || this.volumeInputs.getAicCloudRegion ().isEmpty())) {
throw new ValidationException ("aic-cloud-region");
}
if (version.equals(Constants.SCHEMA_VERSION_V3) && this.volumeInputs.getServiceInstanceId () == null) {
throw new ValidationException ("service-instance-id");
}
if (version.equals(Constants.SCHEMA_VERSION_V3) && this.volumeInputs.getVnfId () == null && ActionType.CREATE_VF_MODULE_VOL.equals(action)) {
throw new ValidationException ("vnf-id");
}
if (ActionType.CREATE.equals (action) || ActionType.CREATE_VF_MODULE_VOL.equals(action)) {
if (this.volumeInputs.getTenantId () == null) {
throw new ValidationException ("tenant-id");
}
}
Object vpN = volumeReq.getVolumeParams ();
if (vpN != null) {
Node node = (Node) vpN;
Document doc = node.getOwnerDocument ();
this.volumeParams = domToStr (doc);
}
msoLogger.debug ("VolumeParams: " + this.volumeParams);
msoLogger.debug ("Request valid");
// Rebuild the request string for BPEL to include request-id
rinfo.setRequestId (this.requestId);
volumeReq.setRequestInfo (rinfo);
StringWriter stringWriter = new StringWriter ();
try {
JAXBContext jaxbContext = JAXBContext.newInstance (VolumeRequest.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
// output pretty printed
jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal (volumeReq, stringWriter);
} catch (JAXBException e) {
msoLogger.debug ("Exception: ", e);
}
this.requestXML = stringWriter.toString ().replace("http://org.openecomp/mso/infra/volume-request",
"http://org.openecomp/mso/infra/vnf-request");
msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
}
public void createRequestRecord (Status status) {
Session session = null;
try {
session = hibernateUtils.getSessionFactory ().openSession ();
session.beginTransaction ();
InfraActiveRequests aq = new InfraActiveRequests ();
aq.setRequestId (requestId);
Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
if (rinfo != null) {
if (rinfo.getAction () != null) {
aq.setAction (rinfo.getAction ().value ());
aq.setRequestAction (RequestActionMap.getMappedRequestAction (rinfo.getAction ().value ()));
}
aq.setSource (rinfo.getSource ());
} else {
// Set up mandatory parameters
aq.setAction (NOT_PROVIDED);
aq.setRequestAction (NOT_PROVIDED);
}
aq.setRequestBody (this.requestXML);
aq.setRequestScope (ModelType.volumeGroup.name ());
if (volumeInputs != null) {
if (volumeInputs.getVolumeGroupId () != null) {
aq.setVolumeGroupId (volumeInputs.getVolumeGroupId ());
}
if (volumeInputs.getVolumeGroupName () != null) {
aq.setVolumeGroupName (volumeInputs.getVolumeGroupName ());
}
if (volumeInputs.getVnfType () != null) {
aq.setVnfType (volumeInputs.getVnfType ());
}
if (volumeInputs.getVnfId () != null) {
aq.setVnfId (volumeInputs.getVnfId ());
}
if (volumeInputs.getServiceInstanceId () != null) {
aq.setServiceInstanceId (volumeInputs.getServiceInstanceId ());
}
if (volumeInputs.getServiceType () != null) {
aq.setServiceType (volumeInputs.getServiceType ());
}
if (volumeInputs.getServiceId () != null) {
aq.setAaiServiceId (volumeInputs.getServiceId ());
}
if (volumeInputs.getAicNodeClli () != null) {
aq.setAicNodeClli (volumeInputs.getAicNodeClli ());
}
if (volumeInputs.getAicCloudRegion () != null) {
aq.setAicCloudRegion (volumeInputs.getAicCloudRegion ());
}
if (volumeInputs.getTenantId () != null) {
aq.setTenantId (volumeInputs.getTenantId ());
}
}
aq.setStartTime (startTimeStamp);
aq.setRequestStatus (status.toString ());
aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER);
aq.setRequestType ("VOLUME");
if (volumeParams != null) {
msoLogger.debug ("Storing volumeParams: " + volumeParams);
aq.setVnfParams (this.volumeParams);
}
if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
aq.setStatusMessage (this.errorMessage);
aq.setResponseBody (this.responseBody);
Timestamp endTimeStamp = new Timestamp (System.currentTimeMillis());
aq.setEndTime (endTimeStamp);
}
aq.setProgress (this.progress);
msoLogger.debug ("About to insert a record");
session.save (aq);
session.getTransaction ().commit ();
session.close ();
} catch (Exception e) {
msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.DataError, "Exception in createRequestRecord", e);
if (session != null) {
session.close ();
}
if (!status.equals (Status.FAILED)) {
throw e;
}
}
}
public void updateFinalStatus (Status status) {
int result = 0;
try {
result = RequestsDatabase.updateInfraFinalStatus(requestId, status.toString (),
this.errorMessage, this.progress, this.responseBody, Constants.MODIFIED_BY_APIHANDLER);
} catch (Exception e) {
msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception in updateFinalStatus");
msoLogger.debug("Exception: ", e);
}
}
public Response buildResponse (int httpResponseCode, String errorCode, InfraActiveRequests inProgress) {
return buildResponseWithError (httpResponseCode, errorCode, inProgress, null);
}
public Response buildResponseWithError (int httpResponseCode,
String errorCode,
InfraActiveRequests inProgress,
String errorString) {
ObjectFactory beansObjectFactory = new ObjectFactory ();
VolumeRequest vr = beansObjectFactory.createVolumeRequest ();
RequestInfo ri = beansObjectFactory.createRequestInfo ();
ri.setRequestId (requestId);
ri.setRequestStatus (this.status);
ri.setAction (this.rinfo.getAction ());
ri.setSource (this.rinfo.getSource ());
String errorMsg = null;
if (errorCode != null) {
// If error code is actually an XML error response from BPEL, treat it specially:
if (!Messages.errors.containsKey (errorCode)) {
if (errorCode.length () > 300) {
errorMsg = errorCode.substring (0, 299);
} else {
errorMsg = errorCode;
}
} else {
if (inProgress == null) {
if (errorCode.equals(ErrorNumbers.RECIPE_DOES_NOT_EXIST)) {
errorMsg = String.format (Messages.errors.get (errorCode), "volume", errorString);
}
else {
errorMsg = String.format (Messages.errors.get (errorCode), errorString);
}
} else if (errorCode.equals (ErrorNumbers.LOCKED_CREATE_ON_THE_SAME_VNF_NAME_IN_PROGRESS)) {
errorMsg = String.format (Messages.errors.get (errorCode),
"volume",
inProgress.getVnfName (),
inProgress.getRequestStatus (),
"volume");
} else if (errorCode.equals (ErrorNumbers.LOCKED_SAME_ACTION_AND_VNF_ID)) {
errorMsg = String.format (Messages.errors.get (errorCode),
"volume",
inProgress.getVnfId (),
inProgress.getRequestStatus (),
inProgress.getAction (),
"volume");
}
}
ri.setStatusMessage (errorMsg);
this.errorMessage = errorMsg;
}
ri.setProgress ((int) this.progress);
Date startDate = new Date (this.startTime);
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS");
String startTimeString = sdf.format (startDate);
ri.setStartTime (startTimeString);
vr.setRequestInfo (ri);
vr.setVolumeInputs (this.volumeInputs);
StringWriter stringWriter = new StringWriter ();
try {
JAXBContext jaxbContext = JAXBContext.newInstance (VolumeRequest.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal (vr, stringWriter);
} catch (JAXBException e) {
msoLogger.debug ("Exception: ", e);
}
String response = stringWriter.toString ();
this.httpResponse = Integer.toString (httpResponseCode);
this.responseBody = response;
// Log the failed request into the MSO Requests database
return Response.status (httpResponseCode).entity (response).build ();
}
public Response buildResponseFailedValidation (int httpResponseCode, String exceptionMessage) {
ObjectFactory beansObjectFactory = new ObjectFactory ();
VolumeRequest vr = beansObjectFactory.createVolumeRequest ();
RequestInfo ri = beansObjectFactory.createRequestInfo ();
ri.setRequestId (requestId);
if (this.rinfo != null) {
if (this.rinfo.getAction () != null) {
ri.setAction (this.rinfo.getAction ());
} else {
ri.setAction (ActionType.NOT_PROVIDED);
}
if (this.rinfo.getSource () != null) {
ri.setSource (this.rinfo.getSource ());
}
} else {
ri.setAction (ActionType.NOT_PROVIDED);
}
// Nothing more is expected for this request
String errorMsg = String.format (Messages.errors.get (ErrorNumbers.REQUEST_FAILED_SCHEMA_VALIDATION
+ "_service"),
exceptionMessage);
ri.setStatusMessage (errorMsg);
this.errorMessage = errorMsg;
ri.setProgress ((int) this.progress);
ri.setRequestStatus (RequestStatusType.FAILED);
Date startDate = new Date (this.startTime);
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS");
String startTimeString = sdf.format (startDate);
ri.setStartTime (startTimeString);
vr.setRequestInfo (ri);
vr.setVolumeInputs (this.volumeInputs);
StringWriter stringWriter = new StringWriter ();
try {
JAXBContext jaxbContext = JAXBContext.newInstance (VolumeRequest.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
// output pretty printed
jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal (vr, stringWriter);
} catch (JAXBException e) {
msoLogger.debug ("Error marshalling", e);
}
String response = stringWriter.toString ();
this.httpResponse = Integer.toString (httpResponseCode);
this.responseBody = response;
return Response.status (httpResponseCode).entity (response).build ();
}
public String getRequestUri () {
return requestUri;
}
public void setRequestUri (String requestUri) {
this.requestUri = requestUri;
}
public VolumeInputs getVolumeInputs () {
return volumeInputs;
}
public RequestInfo getRequestInfo () {
return rinfo;
}
public String getResponseBody () {
return responseBody;
}
public void setResponseBody (String responseBody) {
this.responseBody = responseBody;
}
public String getHttpResponse () {
return httpResponse;
}
public void setHttpResponse (String httpResponse) {
this.httpResponse = httpResponse;
}
public String getRequestId () {
return requestId;
}
public String getRequestXML () {
return requestXML;
}
public void setRequestXML (String requestXML) {
this.requestXML = requestXML;
}
public RequestStatusType getStatus () {
return status;
}
public void setStatus (RequestStatusType status) {
this.status = status;
switch (status) {
case FAILED:
case COMPLETE:
this.progress = Constants.PROGRESS_REQUEST_COMPLETED;
break;
case IN_PROGRESS:
this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS;
break;
}
}
public String getServiceType () {
if (this.volumeInputs.getServiceType () != null)
return this.volumeInputs.getServiceType ();
if (this.volumeInputs.getServiceId () != null)
return this.volumeInputs.getServiceId ();
return null;
}
public static String domToStr (Document doc) {
if (doc == null) {
return null;
}
try {
StringWriter sw = new StringWriter ();
StreamResult sr = new StreamResult (sw);
TransformerFactory tf = TransformerFactory.newInstance ();
Transformer t = tf.newTransformer ();
t.setOutputProperty (OutputKeys.STANDALONE, "yes");
NodeList nl = doc.getDocumentElement ().getChildNodes ();
DOMSource source = null;
for (int x = 0; x < nl.getLength (); x++) {
Node e = nl.item (x);
if (e instanceof Element) {
source = new DOMSource (e);
break;
}
}
if (source != null) {
t.transform (source, sr);
String s = sw.toString ();
return s;
}
return null;
} catch (Exception e) {
msoLogger.error (MessageEnum.APIH_DOM2STR_ERROR, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception in domToStr", e);
}
return null;
}
}
|