2015-09-24 64 views
0

我是bluemix的新手。我下載了客戶端庫。但是我沒有看到Javascript的API文檔。我在哪裏可以找到?我該如何去調用幾個javascript函數,它既不在nodejs客戶端庫中,也不能在網上找到它?Bluemix Nodejs FileTransferStep,文檔

+0

您是否正在嘗試使用特定服務?你引用了哪些客戶端庫?你可以包含一個鏈接,並描述你想達到的目標嗎? – jimmc

+0

我正在嘗試使用workscheduler。我有nodejs庫,但是我沒有找到文檔來了解如何通過Web應用程序與工作負載對象進行交互。例如,我想用憑證調用WorkloadService。提供參數的文檔在哪裏?或者我該如何使用FileTransferStep對象?那有沒有examaples。客戶端庫不包含FileTransfer。謝謝馬里亞諾 – user3189627

回答

1

有關工作負載服務調用你必須編輯您的package.json文件 添加使用HTTPS鏈接IWS光模塊的依賴關係,如下

"dependencies": { 
    "iws-light": "https://start.wa.ibmserviceengage.com/bluemix/iws-light.tgz" 
} 

,那麼你必須打開你的shell ,去你的應用程序的根目錄,然後運行:

npm install

在這之後,你可以要求Workload Scheduler的服務在您的應用程序:

var ws = require("iws-light"); 

,並創建Bluemix連接:

//retrieve service URL from Bluemix VCAP_SERVICES... 
    var wsConn; 
    if(process.env.VCAP_SERVICES) { 
     wsConn = ws.createConnection(); 
    } else { 
     //...or set it on your own(if you're working in local) 
     var url = "your workload scheduler url"; 
     wsConn = ws.createConnection(url); 
    } 

    //retrieve cloud agent 
    var agentName; 
    wsConn.getCloudAgent(function(data) { 
     agentName = data; 
    }); 

    //set your timezone 
    wsConn.setTimezone({timezone: "Europe/Rome"}, function(err, data){ 
     if(err){ 
      console.log(err); 
     } 
    }); 

現在你準備使用的lib,並創建一個過程 ,並給它添加一個FileTransferStep:

//create a process 
    var process = new ws.WAProcess("ProcessName", "This process transfer a file every day from local to remote server"); 

    //supported operations are ws.steps.FileTransferStep.OperationDownload or ws.steps.FileTransferStep.OperationUpload 
    var operation = ws.steps.FileTransferStep.OperationUpload; 


    //create FileTransferStep 
    var ftStep = new ws.steps.FileTransferStep(agentName, operation); 

    //supported protocols are AUTO, FTP, FTPS, SSH, WINDOWS; 
    ftStep.setProtocol(ws.steps.FileTransferStep.ProtocolAuto); 

    //set local file 
    var local = { 
     path: "local file path", 
     user: "local username", 
     password: "local password" 
    }; 
    ftStep.setLocalFile(local.path, local.user, local.password); 

    //set remote file 
    var remote = { 
     path: "remote file path", 
     user: "remote username", 
     password: "remote password", 
     server: "remote server" 
    }; 
    ftStep.setRemoteFile(remote.server, remote.path, remote.user, remote.password); 

    //the binary mode flag: true if it uses FTP binary mode 
    var binaryMode = true; 
    the passive mode flag: true if it uses FTP passive mode 
    var passiveMode = true; 
    //set timeout 
    var timeout = 5; 
    ftStep.setMode(binaryMode, passiveMode , timeout); 

    //add FileTransferStep to the process 
    process.addStep(ftStep); 

    //create a trigger 
    var trigger = new ws.TriggerFactory.everyDayAt(1, 7, 30); 

    //add Trigger to the process 
    process.addTrigger(trigger); 

    process.tasklibraryid = "your task library id"; 

    //create and enable process 
    wsConn.createAndEnableProcess(process, function(err, data){ 
     if(err){ 
      console.log(error); 
     } else{ 
      console.log("process created and enabled"); 
     } 
    }); 

上面的代碼創建一個使用來自node.js代碼的文件傳輸步驟的進程,但是我不確定這是否是您實際需要的。 如果您可以解釋您嘗試實施的方案,則可以更準確地瞭解哪些是使用Workload Scheduler服務實施此方案的最佳方法。

Regards, Gabriele