2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
31 function(alertService, $http, $q, $rootScope) {
33 function checkIfElementType(name) {
35 //This will open the methods located in the app.js
36 if (undefined == name) {
38 }else if (name.toLowerCase().indexOf("policy") >= 0){
41 $rootScope.selectedBoxName = name.toLowerCase();
45 function handleQueryToBackend(def, svcAction, svcUrl, svcPayload) {
47 $http.put(svcUrl, svcPayload).success(
51 if (typeof data.statusCodeValue === 'undefined'
52 || data.statusCodeValue === 200) {
53 alertService.alertMessage(
54 "Action Successful: " + svcAction, 1)
56 if (typeof data.body !== 'undefined') {
57 alertService.alertMessage("Action Failure: "
58 + svcAction + ", " + data.body.errorMessageForUi, 2);
60 alertService.alertMessage("Action Failure: "
63 def.reject(svcAction + " not successful");
69 if (typeof data.body !== 'undefined') {
70 alertService.alertMessage("Action Failure: " + svcAction
71 + ", " + data.body.errorMessageForUi, 2);
74 .alertMessage("Action Failure: " + svcAction, 2);
76 def.reject(svcAction + " not successful");
79 this.toggleDeploy = function(uiAction, modelName, controlNamePrefixIn,
80 bpmnTextIn, propTextIn, svgXmlIn,
81 templateName, typeID, controlNameUuid,
82 modelEventService, deploymentId) {
86 var action = uiAction.toLowerCase();
87 var deployUrl = "/restservices/clds/v1/clds/" + action + "/"
91 controlNamePrefix : controlNamePrefixIn,
92 bpmnText : bpmnTextIn,
93 propText : propTextIn,
95 templateName : templateName,
97 controlNameUuid : controlNameUuid,
98 event : modelEventService,
99 deploymentId : deploymentId
101 handleQueryToBackend(def, action, deployUrl, requestData);
104 this.getModel = function(modelName) {
105 var def = $q.defer();
107 var svcUrl = "/restservices/clds/v2/loop/" + modelName;
108 //var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
109 $http.get(svcUrl).success(function(data) {
110 //var clModel = '{"name": "ClosedLoopTest","lastComputedState":"DESIGN","svgRepresentation": "representation","globalPropertiesJson": [{"name":"service","value":["4cc5b45a-1f63-4194-8100-cd8e14248c92"]},{"name":"vf","value":["07e266fc-49ab-4cd7-8378-ca4676f1b9ec"]},{"name":"actionSet","value":["vnfRecipe"]},{"name":"location","value":["DC1"]},{"name":"deployParameters","value":{"location_id":"","service_id":"","policy_id":"AUTO_GENERATED_POLICY_ID_AT_SUBMIT"}}], "blueprint": "yaml","lastComputedState": "DESIGN","operationalPolicies": [ {"name": "OpPolicyTest", "configurationsJson": { "policy1": [{"name": "pname","value": "policy1"},{"name": "pid","value": "0"},{"name": "timeout","value": "345"},{"policyConfigurations": [[{"name": "recipe","value": ["restart"]},{"name": "maxRetries","value": ["3"]},{"name": "retryTimeLimit","value": ["180"]},{"name": "_id","value": ["6TtHGPq"]},{"name": "parentPolicy","value": [""]},{"name": "actor","value": ["APPC"]},{"name": "recipeInput","value": [""]},{"name": "recipeLevel","value": ["VM"]},{"name": "targetResourceId","value": ["07e266fc-49ab-4cd7-8378-ca4676f1b9ec"]},{"name": "targetResourceIdOther","value": [""]},{"name": "enableGuardPolicy","value": ["on"]},{"name": "guardPolicyType","value": ["GUARD_YAML"]},{"name": "guardTargets","value": [".*"]},{"name": "minGuard","value": ["1"]},{"name": "maxGuard","value": ["1"]},{"name": "limitGuard","value": ["1"]},{"name": "timeUnitsGuard","value": ["minute"]},{"name": "timeWindowGuard","value": ["10"]},{"name": "guardActiveStart","value": ["00:00:01-05:00"]},{"name": "guardActiveEnd","value": ["00:00:00-05:00"]}]]}]} }],"microServicePolicies": [{"name": "tca","properties": "", "shared": true,"policyTosca": "tosca","jsonRepresentation": {"schema":{"title":"DCAE TCA Config","type":"object","required":["name","eventName"],"properties":{"name":{"propertyOrder":101,"title":"Name","type":"string","default":"New_Set"},"eventName":{"propertyOrder":102,"title":"EventName","type":"string","enum":["event1","event2"]},"clSchemaType":{"propertyOrder":103,"title":"Control Loop Schema Type","type":"string","enum":["","type1","type2"]},"threshold":{"propertyOrder":104,"title":"Threshold","format":"tabs","type":"array","items":{"type":"object","title":"Threshold","required":["metric","operator"],"properties":{"metric":{"propertyOrder":1001,"title":"Metric","type":"string","enum":["metric1","metric2"]},"operator":{"propertyOrder":1003,"default":">","title":"Operator","type":"string","enum":[">","<","=","<=",">="]}, "clEventStatus":{"propertyOrder":1004,"title":"Closed Loop Event Status","type":"string","enum":["","ONSET","ABATED"]}}}}}}}}],"loopLogs": [{ } ] }';
111 //cl_props = JSON.parse(clModel);
114 }).error(function(data) {
116 def.reject("Open Model not successful");
120 this.getSavedModel = function() {
122 var def = $q.defer();
124 //var svcUrl = "/restservices/clds/v1/clds/model-names";
125 var svcUrl = "/restservices/clds/v2/loop/getAllNames";
126 $http.get(svcUrl).success(function(data) {
129 }).error(function(data) {
131 def.reject("Open Model not successful");
135 this.setModel = function(modelName, controlNamePrefixIn, bpmnTextIn,
138 var def = $q.defer();
140 var svcUrl = "/restservices/clds/v1/clds/model/" + modelName;
143 controlNamePrefix : controlNamePrefixIn,
144 bpmnText : bpmnTextIn,
145 propText : propTextIn
147 $http.put(svcUrl, svcRequest).success(function(data) {
150 }).error(function(data) {
152 def.reject("Save Model not successful");
156 this.processAction = function(uiAction, modelName, controlNamePrefixIn,
157 bpmnTextIn, propTextIn, svgXmlIn,
158 templateName, typeID, deploymentId) {
160 var def = $q.defer();
162 // console.log(svgXmlIn);
163 var svcUrl = "/restservices/clds/v1/clds/";
164 var svcAction = uiAction.toLowerCase();
165 if (svcAction == "save" || svcAction == "refresh") {
166 svcUrl = svcUrl + "model/" + modelName;
167 } else if (svcAction == "test") {
168 svcUrl = svcUrl + "action/submit/" + modelName + "?test=true";
170 svcUrl = svcUrl + "action/" + svcAction + "/" + modelName;
174 controlNamePrefix : controlNamePrefixIn,
175 bpmnText : bpmnTextIn,
176 propText : propTextIn,
177 imageText : svgXmlIn,
178 templateName : templateName,
180 deploymentId : deploymentId
182 handleQueryToBackend(def, svcAction, svcUrl, svcRequest);
185 this.manageAction = function(modelName, typeId, typeName) {
187 var def = $q.defer();
190 url : "/restservices/clds/v1/clds/getDispatcherInfo",
198 $http(config).success(function(data) {
201 }).error(function(data) {
203 def.reject("manage action not successful");
207 this.processActionResponse = function(modelName) {
209 // populate control name (prefix and uuid here)
210 var headerText = "Closed Loop Modeler - " + modelName;
212 manageCLImage(modelName);
213 enableDisableMenuOptions();
215 this.processRefresh = function(pars) {
218 if (typeof pars.body !== 'undefined') {
221 typeID = newPars.typeId;
222 deploymentId = newPars.deploymentId;
224 enableDisableMenuOptions();
226 function setStatus() {
228 var status = getStatus();
229 // apply color to status
230 var statusColor = 'white';
231 if (status.trim() === "DESIGN") {
233 } else if (status.trim() === "DISTRIBUTED") {
235 } else if (status.trim() === "ACTIVE") {
236 statusColor = 'green'
237 } else if (status.trim() === "STOPPED") {
239 } else if (status.trim() === "DELETING") {
241 } else if (status.trim() === "ERROR") {
242 statusColor = 'orange'
243 } else if (status.trim() === "UNKNOWN") {
248 var statusMsg = '<span style="background-color:'
250 + ';-moz-border-radius: 50px; -webkit-border-radius: 50px; border-radius: 50px;"> '
251 + status + ' </span>';
253 if ($("#status_clds").length >= 1)
254 $("#status_clds").remove();
255 $("#activity_modeler")
257 '<span id="status_clds" style="position: absolute; left: 61%;top: 151px; font-size:20px;">Status: '
258 + statusMsg + '</span>');
260 function manageCLImage(modelName) {
261 getModelImage(modelName).then(function(pars) {
262 //var svg='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/2000/svg"> <defs> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="11" refY="10" id="markerSjdype4kmnw"> <path d="M 1 5 L 11 10 L 1 15 Z" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="20" markerHeight="20" orient="auto" refX="6" refY="6" id="markerSjdype4kmny"> <circle cx="6" cy="6" r="3.5" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="20" markerHeight="20" orient="auto" refX="8.5" refY="5" id="markerSjdype4kmo0"> <path d="m 1 5 l 0 -3 l 7 3 l -7 3 z" style="stroke-width: 1; stroke-linecap: butt; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="11" refY="10" id="markerSjdype4kmo2"> <path d="M 1 5 L 11 10 L 1 15" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="-1" refY="10" id="markerSjdype4kmo4"> <path d="M 0 10 L 8 6 L 16 10 L 8 14 Z" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#ffffff" stroke="#000000" /> </marker> <marker viewBox="0 0 20 20" markerWidth="10" markerHeight="10" orient="auto" refX="-5" refY="10" id="markerSjdype4kmo6"> <path d="M 1 4 L 5 16" style="stroke-width: 1; stroke-linecap: round; stroke-dasharray: 10000, 1;" fill="#000000" stroke="#000000" /> </marker> </defs><g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="start-circle" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g shape-rendering="geometricPrecision" text-rendering="optimizeQuality" stroke-width="2"> <circle fill="none" r="17" cx="34" cy="41"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="Arrow_d0b22360-770d-4b05-b81c-cf148b121341" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g shape-rendering="geometricPrecision" text-rendering="optimizeQuality" stroke-width="2"> <line y2="41" fill="none" x1="51" x2="170" y1="41"/> <polygon fill="none" points=" 166 38 166 44 172 41"/> <polygon points=" 166 38 166 44 172 41" stroke="none"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="VES" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g shape-rendering="geometricPrecision" text-rendering="optimizeQuality" stroke-width="2"> <rect fill="none" x="174" width="123" y="1" height="82"/> </g> <g fill-opacity="0" fill="rgb(0,0,0)" text-rendering="optimizeQuality" shape-rendering="geometricPrecision" stroke="rgb(0,0,0)" stroke-opacity="0" stroke-width="2"> <rect x="174" width="123" y="1" height="82" stroke="none"/> </g> <g font-family="sans-serif" shape-rendering="geometricPrecision" text-rendering="optimizeQuality"> <text x="223" xml:space="preserve" y="42" stroke="none">VES</text> <line y2="83" fill="none" stroke-width="2" x1="194" x2="194" y1="1"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="Arrow_d4351927-d77a-4e04-82d1-cd8f2b008137" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <line y2="41" fill="none" x1="297" x2="416" y1="41"/> <polygon fill="none" points=" 412 38 412 44 418 41"/> <polygon points=" 412 38 412 44 418 41" stroke="none"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="TCA" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <rect fill="none" x="420" width="123" y="1" height="82"/> </g> <g fill-opacity="0" fill="rgb(0,0,0)" text-rendering="optimizeQuality" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="rgb(0,0,0)" stroke-opacity="0" stroke-width="2"> <rect x="420" width="123" y="1" height="82" stroke="none"/> </g> <g font-family="sans-serif" shape-rendering="geometricPrecision" text-rendering="optimizeQuality"> <text x="470" xml:space="preserve" y="42" stroke="none">TCA</text> <line y2="62" fill="none" stroke-width="2" x1="420" x2="543" y1="62"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="Arrow_5ae2966f-f971-4c3b-8237-efa551beb531" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <line y2="41" fill="none" x1="543" x2="662" y1="41"/> <polygon fill="none" points=" 658 38 658 44 664 41"/> <polygon points=" 658 38 658 44 664 41" stroke="none"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="Policy" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <rect fill="none" x="666" width="123" y="1" height="82"/> </g> <g fill-opacity="0" fill="rgb(0,0,0)" text-rendering="optimizeQuality" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="rgb(0,0,0)" stroke-opacity="0" stroke-width="2"> <rect x="666" width="123" y="1" height="82" stroke="none"/> </g> <g font-family="sans-serif" shape-rendering="geometricPrecision" text-rendering="optimizeQuality"> <text x="710" xml:space="preserve" y="42" stroke="none">Policy</text> <line y2="1" fill="none" stroke-width="2" x1="666" x2="727" y1="42"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="Arrow_ed5ccaed-6d8c-44e9-8245-85f66523cb44" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="2" shape-rendering="geometricPrecision" font-family="sans-serif"> <line y2="41" fill="none" x1="789" x2="908" y1="41"/> <polygon fill="none" points=" 904 38 904 44 910 41"/> <polygon points=" 904 38 904 44 910 41" stroke="none"/> </g> </g> </g> <g fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" font-family="'Dialog'" font-style="normal" data-element-id="circle_stop" stroke-linejoin="miter" font-size="12px" image-rendering="auto" stroke-dashoffset="0"><!--Generated by the Batik Graphics2D SVG Generator--> <defs id="genericDefs"/> <g> <g text-rendering="optimizeQuality" stroke-width="4" shape-rendering="geometricPrecision" font-family="sans-serif"> <circle fill="none" r="17" cx="929" cy="41"/> </g> </g> </g> </svg>';
264 if ($("#svgContainer").length > 0)
265 $("#svgContainer").remove();
266 $("#js-canvas").append(
267 "<span id=\"svgContainer\">" + svg + "</span>");
268 $("#svgContainer svg").attr('width', '100%');
269 $("#svgContainer svg").attr('height', '100%');
270 $("#svgContainer").click(
272 console.log("svgContainer:" + $("#svgContainer svg"));
273 var name = $($($($(event.target).parent()).parent()).parent()).attr("data-element-id")
274 lastElementSelected = $($(event.target).parent()).attr(
276 checkIfElementType(name)
281 enableDisableMenuOptions = function() {
283 //var status = getStatus();
284 //enableActionMenu(status);
285 enableAllActionMenu();
287 getModelImage = function(modelName) {
288 var def = $q.defer();
290 var svcUrl = "/restservices/clds/v2/loop/svgRepresentation/" + modelName;
291 $http.get(svcUrl).success(function(data) {
293 }).error(function(data) {
294 def.reject("Not able to get the model image");