Java調用Azkaban的RestFul接口

一、繞過ssl認證的工具類:java

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public final class SSLUtil {

    private static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] { new X509TrustManager() {

        public java.security.cert.X509Certificate[] getAcceptedIssuers()
        {
            return null;
        }

        public void checkClientTrusted(X509Certificate[] certs, String authType)
        {
        }

        public void checkServerTrusted(X509Certificate[] certs, String authType)
        {
        }
    } };

    public static void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException
    {
        final SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, UNQUESTIONING_TRUST_MANAGER, null);
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    }

    public static void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException
    {
        SSLContext.getInstance("SSL").init(null, null, null);
    }

    private SSLUtil()
    {
        throw new UnsupportedOperationException("Do not instantiate libraries.");
    }
}

二、直接測試類:git

import java.io.File;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class AzkabanTest {

    private static final String API = "http://172.16.4.117:9091";

    private static final String SESSION_ID = "6102b053-8720-4940-8baf-0bed38748821";

    private static final String PROJECT = "test";

    private static final String PROJECT_ID = "12";

    private static final String SCHEDULE_ID = "13";

    private static RestTemplate restTemplate = null;

    static
    {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(2000);
        requestFactory.setReadTimeout(2000);
        restTemplate = new RestTemplate(requestFactory);
    }

    public static void main(String[] args) throws Exception
    {
        loginTest(); // 登陸
        // createProTest(); // 建立Project
        // deleteProTest(); // 刪除Project
        // uploadZip(); // 上傳zip
        // scheduleEXEaFlowTest(); // 建立定時任務
        // scheduleByCronEXEaFlowTest(); // 建立定時任務cron
        // unscheduleFlowTest(); // 取消定時任務
    }

    /**
     * 登陸測試 登陸調度系統
     */
    public static void loginTest() throws Exception
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        hs.add("X-Requested-With", "XMLHttpRequest");
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("action", "login");
        linkedMultiValueMap.add("username", "azkaban");
        linkedMultiValueMap.add("password", "azkaban");

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String postForObject = restTemplate.postForObject(API, httpEntity, String.class);
        System.out.println(postForObject);
    }

    /**
     * 建立任務測試 建立一個project
     */
    public static void createProTest() throws Exception
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        hs.add("X-Requested-With", "XMLHttpRequest");
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", SESSION_ID);
        linkedMultiValueMap.add("action", "create");
        linkedMultiValueMap.add("name", PROJECT);
        linkedMultiValueMap.add("description", "testproject");

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String postForObject = restTemplate.postForObject(API + "/manager", httpEntity, String.class);
        System.out.println(postForObject);
    }

    /**
     * 刪除任務測試 刪除一個project
     */
    public static void deleteProTest() throws Exception
    {

        SSLUtil.turnOffSslChecking();

        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        hs.add("X-Requested-With", "XMLHttpRequest");
        hs.add("Accept", "text/plain;charset=utf-8");

        Map<String, String> map = new HashMap<>();

        map.put("id", SESSION_ID);
        map.put("project", PROJECT);

        ResponseEntity<String> exchange = restTemplate.exchange(API + "/manager?session.id={id}&delete=true&project={project}", HttpMethod.GET, new HttpEntity<String>(hs), String.class, map);

        System.out.println(exchange.getBody());
        System.out.println(exchange.getStatusCode());
        System.out.println(exchange.getStatusCodeValue());
    }

    /**
     * 上傳zip 上傳依賴文件 zip包
     */
    public static void uploadZip() throws Exception
    {
        SSLUtil.turnOffSslChecking();
        FileSystemResource resource = new FileSystemResource(new File("C:/Users/wuzy/Desktop/1.zip"));
        LinkedMultiValueMap<String, Object> linkedMultiValueMap = new LinkedMultiValueMap<String, Object>();
        linkedMultiValueMap.add("session.id", SESSION_ID);
        linkedMultiValueMap.add("ajax", "upload");
        linkedMultiValueMap.add("project", PROJECT);
        linkedMultiValueMap.add("file", resource);
        String postForObject = restTemplate.postForObject(API + "/manager", linkedMultiValueMap, String.class);
        System.out.println(postForObject);
    }

    /**
     * Schedule a period-based Flow 根據時間 建立調度任務
     */
    public static void scheduleEXEaFlowTest() throws KeyManagementException, NoSuchAlgorithmException
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        hs.add("X-Requested-With", "XMLHttpRequest");
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", SESSION_ID);
        linkedMultiValueMap.add("ajax", "scheduleFlow");
        linkedMultiValueMap.add("projectName", PROJECT);
        linkedMultiValueMap.add("projectId", PROJECT_ID);

        linkedMultiValueMap.add("flow", "2");
        // linkedMultiValueMap.add("scheduleTime", "10,28,am,EDT");
        linkedMultiValueMap.add("scheduleTime", "15,08,pm,PDT");
        linkedMultiValueMap.add("scheduleDate", "12/1/2017");
        linkedMultiValueMap.add("flowName", "test01 description");

        // 是否循環
        linkedMultiValueMap.add("is_recurring", "on");

        // 循環週期 天 年 月等
        // M Months
        // w Weeks
        // d Days
        // h Hours
        // m Minutes
        // s Seconds
        linkedMultiValueMap.add("period", "30s"); // 經測試,定時任務支持至少是60秒或其整數倍

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String postForObject = restTemplate.postForObject(API + "/schedule", httpEntity, String.class);
        System.out.println(postForObject);
    }

    /**
     * Flexible scheduling using Cron 經過cron表達式調度執行 建立調度任務
     */
    public static void scheduleByCronEXEaFlowTest() throws KeyManagementException, NoSuchAlgorithmException
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        hs.add("X-Requested-With", "XMLHttpRequest");
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", SESSION_ID);
        linkedMultiValueMap.add("ajax", "scheduleCronFlow");
        linkedMultiValueMap.add("projectName", PROJECT);
        linkedMultiValueMap.add("cronExpression", "* */1 * * * ?");
        linkedMultiValueMap.add("flow", "中文");
        linkedMultiValueMap.add("flowName", "dsaf");

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String postForObject = restTemplate.postForObject(API + "/schedule", httpEntity, String.class);
        System.out.println(postForObject);
    }

    /**
     * Unschedule a Flow 取消一個流的調度
     */
    public static void unscheduleFlowTest() throws KeyManagementException, NoSuchAlgorithmException
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        hs.add("X-Requested-With", "XMLHttpRequest");
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", SESSION_ID);
        linkedMultiValueMap.add("action", "removeSched");
        linkedMultiValueMap.add("scheduleId", SCHEDULE_ID);

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String postForObject = restTemplate.postForObject(API + "/schedule", httpEntity, String.class);
        System.out.println(postForObject);
    }

}

三、Spring Boot接口測試:github

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class AzkabanConfig {

    @Bean
    public RestTemplate getRestTemplate()
    {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(2000);
        requestFactory.setReadTimeout(2000);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        return restTemplate;
    }

}
import java.io.File;
import java.util.Date;

public interface IAzkabanService {

    /**
     * Azkaban登陸接口,返回sessionId
     * @author wuzy
     * @date 2017年12月21日
     * @return
     * @throws Exception
     */
    public String login() throws Exception;

    /**
     * Azkaban建立project
     * @author wuzy
     * @date 2017年12月21日
     * @param projectName project名稱
     * @param description project描述
     * @throws Exception
     */
    public void createProject(String projectName, String description) throws Exception;

    /**
     * Azkaban刪除project
     * @author wuzy
     * @date 2017年12月21日
     * @param projectName project名稱
     * @throws Exception
     */
    public void deleteProject(String projectName) throws Exception;

    /**
     * Azkaban上傳zip文件
     * @author wuzy
     * @date 2017年12月21日
     * @param projectName
     * @param file
     * @return projectId
     * @throws Exception
     */
    public String uploadZip(String projectName, File file) throws Exception;

    /**
     * 根據時間 建立調度任務
     * @author wuzy
     * @date 2017年12月21日
     * @param projectId
     * @param projectName
     * @param flow
     * @param flowName
     * @param recurring 是否循環,on循環
     * @param period 循環頻率: M Months,w Weeks,d Days,h Hours,m Minutes,s Seconds;如60s,支持分鐘的倍數
     * @param date 開始時間
     * @return 返回scheduleId
     * @throws Exception
     */
    public String scheduleEXEaFlow(String projectId, String projectName, String flow, String flowName, String recurring, String period, Date date) throws Exception;

    /**
     * 根據cron表達式 建立調度任務
     * @author wuzy
     * @date 2017年12月21日
     * @param projectName
     * @param cron
     * @param flow
     * @param flowName
     * @return 返回scheduleId
     * @throws Exception
     */
    public String scheduleByCronEXEaFlow(String projectName, String cron, String flow, String flowName) throws Exception;

    /**
     * 根據scheduleId取消一個流的調度
     * @author wuzy
     * @date 2017年12月21日
     * @param scheduleId
     * @throws Exception
     */
    public void unscheduleFlow(String scheduleId) throws Exception;

    /**
     * 下載Azkaban壓縮文件
     * @author wuzy
     * @date 2017年12月22日
     * @param projectName
     * @param zipPath
     * @throws Exception
     */
    public void downLoadZip(String projectName, String zipPath) throws Exception;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ueb.baseplatform.scheduling.common.Constant;
import com.ueb.baseplatform.scheduling.disconf.GlobalConfig;
import com.ueb.baseplatform.scheduling.service.IAzkabanService;
import com.ueb.baseplatform.scheduling.util.SSLUtil;

@Service
public class AzkabanServiceImpl implements IAzkabanService {

    private static final Logger logger = LoggerFactory.getLogger(AzkabanServiceImpl.class);

    private static final String CONTENT_TYPE = "application/x-www-form-urlencoded; charset=utf-8";

    private static final String X_REQUESTED_WITH = "XMLHttpRequest";

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private GlobalConfig globalConfig;

    @Override
    public String login() throws Exception
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", CONTENT_TYPE);
        hs.add("X-Requested-With", X_REQUESTED_WITH);
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("action", "login");
        linkedMultiValueMap.add("username", globalConfig.getAzkUsername());
        linkedMultiValueMap.add("password", globalConfig.getAzkPassword());

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String result = restTemplate.postForObject(globalConfig.getAzkUrl(), httpEntity, String.class);

        logger.info("--------Azkaban返回登陸信息:" + result);

        return new Gson().fromJson(result, JsonObject.class).get("session.id").getAsString();
    }

    @Override
    public void createProject(String projectName, String description) throws Exception
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", CONTENT_TYPE);
        hs.add("X-Requested-With", X_REQUESTED_WITH);
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", login());
        linkedMultiValueMap.add("action", "create");
        linkedMultiValueMap.add("name", projectName);
        linkedMultiValueMap.add("description", description);

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String result = restTemplate.postForObject(globalConfig.getAzkUrl() + "/manager", httpEntity, String.class);

        logger.info("--------Azkaban返回建立Project信息:" + result);

        // 建立成功和已存在,都表示建立成功
        if (!Constant.AZK_SUCCESS.equals(new Gson().fromJson(result, JsonObject.class).get("status").getAsString()))
        {
            if (!"Project already exists.".equals(new Gson().fromJson(result, JsonObject.class).get("message").getAsString()))
            {
                throw new Exception("建立Azkaban Project失敗");
            }
        }
    }

    @Override
    public void deleteProject(String projectName) throws Exception
    {
        SSLUtil.turnOffSslChecking();

        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", CONTENT_TYPE);
        hs.add("X-Requested-With", X_REQUESTED_WITH);
        hs.add("Accept", "text/plain;charset=utf-8");

        Map<String, String> map = new HashMap<>();

        map.put("id", login());
        map.put("project", projectName);

        ResponseEntity<String> exchange = restTemplate.exchange(globalConfig.getAzkUrl() + "/manager?session.id={id}&delete=true&project={project}", HttpMethod.GET, new HttpEntity<String>(hs),
                String.class, map);

        logger.info("--------Azkaban返回刪除Azkaban Project信息:" + exchange);

        if (HttpStatus.SC_OK != exchange.getStatusCodeValue())
        {
            throw new Exception("刪除Azkaban Project失敗");
        }
    }

    @Override
    public String uploadZip(String projectName, File file) throws Exception
    {
        SSLUtil.turnOffSslChecking();
        FileSystemResource resource = new FileSystemResource(file);
        LinkedMultiValueMap<String, Object> linkedMultiValueMap = new LinkedMultiValueMap<String, Object>();
        linkedMultiValueMap.add("session.id", login());
        linkedMultiValueMap.add("ajax", "upload");
        linkedMultiValueMap.add("project", projectName);
        linkedMultiValueMap.add("file", resource);
        String result = restTemplate.postForObject(globalConfig.getAzkUrl() + "/manager", linkedMultiValueMap, String.class);

        logger.info("--------Azkaban返回上傳文件信息:" + result);

        if (StringUtils.isEmpty(new Gson().fromJson(result, JsonObject.class).get("projectId").getAsString()))
        {
            throw new Exception("上傳文件至Azkaban失敗");
        }

        return new Gson().fromJson(result, JsonObject.class).get("projectId").getAsString();
    }

    @Override
    public String scheduleEXEaFlow(String projectId, String projectName, String flow, String flowName, String recurring, String period, Date date) throws Exception
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", CONTENT_TYPE);
        hs.add("X-Requested-With", X_REQUESTED_WITH);
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", login());
        linkedMultiValueMap.add("ajax", "scheduleFlow");
        linkedMultiValueMap.add("projectName", projectName);
        linkedMultiValueMap.add("projectId", projectId);
        linkedMultiValueMap.add("flow", flow);
        linkedMultiValueMap.add("flowName", flowName);
        linkedMultiValueMap.add("is_recurring", recurring);
        linkedMultiValueMap.add("period", period);
        scheduleTimeInit(linkedMultiValueMap, date);

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String result = restTemplate.postForObject(globalConfig.getAzkUrl() + "/schedule", httpEntity, String.class);

        logger.info("--------Azkaban返回根據時間建立定時任務信息:" + result);

        if (!Constant.AZK_SUCCESS.equals(new Gson().fromJson(result, JsonObject.class).get("status").getAsString()) || new Gson().fromJson(result, JsonObject.class).get("scheduleId").getAsInt() < 0)
        {
            throw new Exception("根據時間建立定時任務失敗");
        }

        return new Gson().fromJson(result, JsonObject.class).get("scheduleId").getAsString();
    }

    private void scheduleTimeInit(LinkedMultiValueMap<String, String> linkedMultiValueMap, Date date)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Integer year = calendar.get(Calendar.YEAR);
        Integer month = calendar.get(Calendar.MONTH) + 1;
        Integer day = calendar.get(Calendar.DATE);
        Integer hour = calendar.get(Calendar.HOUR_OF_DAY);
        Integer minute = calendar.get(Calendar.MINUTE);

        linkedMultiValueMap.add("scheduleTime", hour + "," + minute + (hour > 11 ? ",pm,PDT" : ",am,EDT"));
        linkedMultiValueMap.add("scheduleDate", month + "/" + day + "/" + year);
    }

    @Override
    public String scheduleByCronEXEaFlow(String projectName, String cron, String flow, String flowName) throws Exception
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", CONTENT_TYPE);
        hs.add("X-Requested-With", X_REQUESTED_WITH);
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", login());
        linkedMultiValueMap.add("ajax", "scheduleCronFlow");
        linkedMultiValueMap.add("projectName", projectName);
        linkedMultiValueMap.add("cronExpression", cron);
        linkedMultiValueMap.add("flow", flow);
        linkedMultiValueMap.add("flowName", flowName);

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String result = restTemplate.postForObject(globalConfig.getAzkUrl() + "/schedule", httpEntity, String.class);

        logger.info("--------Azkaban返回根據cron表達式建立定時任務信息:" + result);

        if (!Constant.AZK_SUCCESS.equals(new Gson().fromJson(result, JsonObject.class).get("status").getAsString()))
        {
            throw new Exception("根據cron表達式建立定時任務失敗");
        }

        return new Gson().fromJson(result, JsonObject.class).get("scheduleId").getAsString();
    }

    @Override
    public void unscheduleFlow(String scheduleId) throws Exception
    {
        SSLUtil.turnOffSslChecking();
        HttpHeaders hs = new HttpHeaders();
        hs.add("Content-Type", CONTENT_TYPE);
        hs.add("X-Requested-With", X_REQUESTED_WITH);
        LinkedMultiValueMap<String, String> linkedMultiValueMap = new LinkedMultiValueMap<String, String>();
        linkedMultiValueMap.add("session.id", login());
        linkedMultiValueMap.add("action", "removeSched");
        linkedMultiValueMap.add("scheduleId", scheduleId);

        HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(linkedMultiValueMap, hs);
        String result = restTemplate.postForObject(globalConfig.getAzkUrl() + "/schedule", httpEntity, String.class);

        logger.info("--------Azkaban返回取消流調度信息:" + result);

        if (!Constant.AZK_SUCCESS.equals(new Gson().fromJson(result, JsonObject.class).get("status").getAsString()))
        {
            throw new Exception("根據cron表達式建立定時任務失敗");
        }
    }

    @Override
    public void downLoadZip(String projectName, String zipPath)
    {
        OutputStream output = null;
        BufferedOutputStream bufferedOutput = null;

        try
        {
            URL url = new URL(globalConfig.getAzkUrl() + "/manager?session.id=" + login() + "&download=true&project=" + projectName);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(3 * 1000);
            InputStream inputStream = conn.getInputStream();
            File file = new File(zipPath);
            output = new FileOutputStream(file);
            bufferedOutput = new BufferedOutputStream(output);
            bufferedOutput.write(IOUtils.toByteArray(inputStream));
        }
        catch (Exception e)
        {
            logger.info("--------下載Azkaban壓縮文件異常:" + e.getMessage(), e);
        }
        finally
        {
            if (bufferedOutput != null)
            {
                try
                {
                    bufferedOutput.flush();
                    bufferedOutput.close();
                }
                catch (IOException e)
                {
                    logger.info("關閉流異常:" + e.getMessage(), e);
                }
            }

            if (output != null)
            {
                try
                {
                    output.close();
                }
                catch (IOException e)
                {
                    logger.info("關閉流異常:" + e.getMessage(), e);
                }
            }
        }

    }

}

PS:Azkaban Github API:http://azkaban.github.io/azkaban/docs/latest/#ajax-apiweb

相關文章
相關標籤/搜索