2 ============LICENSE_START=======================================================
3 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 ================================================================================
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ============LICENSE_END=========================================================
19 console.log("loading dcae-mod");
24 * @desc: on load of page, makes submit button disabled. Also makes an api call to get the host IP of the current instance
26 $(document).ready(function (){
27 if(dt_id == null){ $('#operate-submit-btn').prop('disabled', true); }
29 getDistributionTargets();
33 * common function to reuse : invokes api to get new updates list environments.
34 * @desc: Makes the select dropdown empty first. Then manually add Placeholder as first/default Option.
35 * And then dynamically add list of Environments as Options.
37 function getDistributionTargets(){
38 var select = document.getElementById("environmentType");
39 if(select && select.options && select.options.length > 0){
40 select.options.length=0;
41 var element= document.createElement("option");
42 element.textContent= "Select Environment";
43 element.selected=true;
44 element.disabled=true;
45 element.className="combo-option-text";
46 select.appendChild(element);
51 url: '/distributor/distribution-targets',
53 contentType: 'application/json',
54 success: function(data){
56 for(var i=0; i < data.distributionTargets.length; i++){
57 var opt= data.distributionTargets[i];
58 var element= document.createElement("option");
59 element.textContent= opt.name;
60 element.value= opt.id;
61 element.className="combo-option-text";
62 select.appendChild(element);
70 * @desc: submit button functionality to distribute/POST process group to the environment.
72 var distributeGraph = function(){
73 var selected_id = $('#operation-context-id').text();
74 // process group id (nifi api) != flow id (nifi registry api)
75 // so must first fetch the flow id from nifi api
78 url: '../nifi-api/process-groups/'+selected_id,
79 contentType: 'application/json',
80 success: function(data) {
81 const flow_id = data["component"]["versionControlInformation"]["flowId"];
82 const request = {"processGroupId": flow_id}
86 data: JSON.stringify(request),
87 url: '/distributor/distribution-targets/'+dt_id+'/process-groups',
89 contentType: 'application/json',
90 success: function(data){
91 alert("Success, Your flow have been distributed successfully");
93 error: function(err) {
94 alert("Issue with distribution:\n\n" + JSON.stringify(err, null, 2));
103 * @desc: selection of distribution target environment to post the process group
105 var onEnvironmentSelect = function(){
106 dt_id = $('#environmentType').val();
108 if(dt_id == null){ $('#operate-submit-btn').prop('disabled', true); }
109 else{ $('#operate-submit-btn').prop('disabled', false); }
114 * @desc: event handler for Refresh icon in Operate panel : invokes api to refresh the list of Envs
116 var refreshEnvironments= function(){ getDistributionTargets(); };
120 * @desc: event handler for Close icon of Setting/ Distribution Env CRUD dialog : invokes api to refresh the list of Envs
122 var onCloseSettings= function(){ getDistributionTargets(); };
125 function uecvalue(n) {
126 return encodeURIComponent("" + $(n).val());
130 return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
134 $("#onboarding-in-progress").show();
135 var url = "/acumos-adapter/onboard.js?acumos=" + uecvalue("#furl");
136 if ($("#cat-menu").val() != "*") {
137 url += "&catalogId=" + uecvalue("#cat-menu");
138 if ($("#sol-menu").val() != "*") {
139 url += "&solutionId=" + uecvalue("#sol-menu");
140 if ($("#rev-menu").val() != "*") {
141 url += "&revisionId=" + uecvalue("#rev-menu");
145 var xhr = new XMLHttpRequest();
146 xhr.onerror = function() {
147 $("#onboarding-in-progress").hide();
148 alert("Onboarding failed");
150 xhr.onload = function() {
151 if (this.status < 400) {
152 $("#onboarding-in-progress").hide();
153 alert("Onboarding successful");
155 alert("Onboarding error: " + this.statusText);
158 xhr.open("POST", url);
162 function chooseSolution() {
163 if ($("#sol-menu").val() == "*") {
166 lookupItem("#ac-revs", "#rev-menu", "/acumos-adapter/listRevisions.js?acumos=" + uecvalue("#furl") + "&solutionId=" + uecvalue("#sol-menu"));
170 function chooseCatalog() {
171 if ($("#cat-menu").val() == "*") {
174 lookupItem("#ac-sols", "#sol-menu", "/acumos-adapter/listSolutions.js?acumos=" + uecvalue("#furl") + "&catalogId=" + uecvalue("#cat-menu"));
178 function lookupCatalogs() {
179 $("#onboard").show();
180 lookupItem("#c-acumos", "#cat-menu", "/acumos-adapter/listCatalogs.js?acumos=" + uecvalue("#furl"));
183 function lookupItem(dblock, smenu, url) {
184 var xhr = new XMLHttpRequest();
185 var xmenu = $(smenu);
186 xmenu[0].options.length = 1;
188 xhr.onerror = function() {
189 alert("Error querying remote Acumos system");
192 xhr.onload = function() {
193 var xresp = JSON.parse(this.response);
195 for (i = 0; i < xresp.length; i++) {
196 var option = document.createElement("option");
197 option.text = esc(xresp[i].name);
198 option.value = xresp[i].id;
199 xmenu[0].add(option);
201 if (xresp.length == 0) {
208 xhr.open("GET", url);
212 function setModelType() {
213 if ($("#model-type").val() == "mtAcumos") {
215 $("#mt-acumos").show();
220 function _updatevis() {
221 if ($("#model-type").val() != "mtAcumos") {
222 $("#mt-acumos").hide();
225 if ($("#furl").val() == "") {
226 $("#c-acumos").hide();
227 $("#onboard").hide();
228 $("#cat-menu").val("*");
230 if ($("#cat-menu").val() == "*") {
231 $("#ac-sols").hide();
232 $("#sol-menu").val("");
234 if ($("#sol-menu").val() == "*") {
235 $("#ac-revs").hide();
236 $("#rev-menu").val("");
240 function onBoardComponent() {
241 _onBoardFile("#cspec", "/onboarding/components");
244 function onBoardDataFormat() {
245 _onBoardFile("#dfspec", "/onboarding/dataformats");
248 function _onBoardFile(source, url) {
249 reader = new FileReader();
250 reader.onerror = function() {
251 alert("Error reading file");
253 reader.onload = function(evt) {
254 xhr = new XMLHttpRequest();
255 xhr.onload = function() {
256 if (this.status >= 400) {
257 alert("File upload failed " + this.statusText);
259 alert("File upload complete");
262 xhr.onerror = function() {
263 alert("File upload failed");
265 xhr.open("POST", url);
266 xhr.overrideMimeType("application/json");
267 xhr.send(evt.target.result);
269 reader.readAsBinaryString($(source)[0].files[0]);