he following script imports application blueprints from XML files into vFabric Application Director v5.2
var strFolderPath; strFolderPath = "C:\\vFabricExport\\" + intYear + "\\" + intMonth + "\\"; var objFile; objFile = new File(strFolderPath); var arrFile; arrFile = objFile.list(".export"); var strFiles; strFiles = ""; var strFileSearch; strFileSearch = intYear + "-" + intMonth + "-" + intDay + "-" + intHour + "-"; System.log("===== File Search = " + strFileSearch); for ( var i = 0; i < arrFile.length; i++ ) { var strFile; strFile = arrFile[i]; System.log("===== Attempting To Find: " + strFile); var objFileReader; objFileReader = new FileReader(strFolderPath + strFile); if ( objFileReader.exists == true ) { System.log("===== Found File: " + strFile); objFileReader.open(); var strFileContent; strFileContent = objFileReader.readAll(); var strJson; strJson = ''; strJson += '{'; strJson += ' "exportPackage": "' + strFileContent + '",'; strJson += ' "conflictResolutionAction": "OVERWRITE",'; strJson += ' "importAsNewSuffix": ""'; strJson += '}'; var objRESTRequest; objRESTRequest = objRESTOperationVFabricImport.createRequest([], strJson); objRESTRequest.contentType = "application/json"; objRESTRequest.setHeader("Accept","application/json"); var objRESTResponse; objRESTResponse = objRESTRequest.execute(); if ( objRESTResponse.statusCode == 200 ) { var strContentAsString; strContentAsString = objRESTResponse.contentAsString; var objJSON; objJSON = JSON.parse(strContentAsString); if ( objJSON.errors == false ) { System.log("===== Successfully Imported: " + strFile); } else { System.error("===== Failed To Imported: " + strFile); System.error("=================================================="); var arrMessageList; arrMessageList = objJSON.messageList; for ( var j = 0; j < arrMessageList.length; j++ ) { var objMessage; objMessage = arrMessageList[j];
objCustomActions.EMailMessage("<h2>vFabric Application Director</h2><p>Reported an error parsing the JSON returned.</p><h3>The Reported Errors Are:</h3><p></p><h4>The Original Response Was</h4><p></p>");
System.error("===== JSON Error: " + objJSONApplication.errors); } System.error("=================================================="); } } else { objCustomActions.EMailMessage("<h2>vFabric Application Director</h2><p>Reported a HTTP Error Code: " + objRESTResponse.statusCode + ".</p><h4>The Original Response Was</h4><p></p>"); System.error("===== HTTP Error: " + objRESTResponse.statusCode); throw "HTTP Error: " + objRESTResponse.statusCode; } } }