如何通过更改开始和结束日期重新提交Oozi协调员?

时间:2016-05-31 11:18:56

标签: oozie-coordinator

hue 中有没有办法重新提交Oozie的协调员

我有一名协调员每天从2016年1月1日至2016年1月30日期间运行。

现在,我想将日期从1-2-2016动态更改为28-2-2016。

有没有办法动态更改开始和结束日期而不停止协调器抛出Java代码或任何其他方式?

以下是我的Java代码,但它不起作用 - PUT请求给我一个错误

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class JobSchedule {
    public static void main(String arg[]) throws Exception {

        // oozie.coord.application.path
        // hdfs://nameservice1/user/hue/oozie/workspaces/hue-oozie-1464585998.59

        // String GetData =
        // "curl -XGET http://localhost:11000/oozie/v2/job/0021784-160502160551671-oozie-oozi-C?show=info&timezone=UTC";
        HttpURLConnection connection = null;
        String request = "http://localhost:11000/oozie/v2/job/0023481-160502160551671-oozie-oozi-C?show=info&timezone=UTC";
        URL url = new URL(request);
        StringBuffer output = new StringBuffer();
        Date End = null;
        Date start = null;
        try {
            connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setInstanceFollowRedirects(false);
            connection.setRequestMethod("GET");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("charset", "utf-8");
            // connection.setUseCaches(false);
            Gson gson = new Gson();

            OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());
            osw.write(request);
            osw.flush();

            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

            String line = "";

            while ((line = reader.readLine()) != null) {
                output.append(line + "\n");
            }

            osw.close();
            reader.close();
            JsonObject jsonObject = (JsonObject) gson.fromJson(output.toString(), JsonObject.class);
            String Ed = jsonObject.get("endTime").toString();
            End = new Date(Ed);
            String Sd = jsonObject.get("startTime").toString();
            start = new Date(Sd);

        } catch (Exception e) {
            e.printStackTrace();
        }
        connection.disconnect();

        String Data = null;

        Calendar sc = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'00:00:ss.SSSzzz");
        sc.set(Calendar.DAY_OF_MONTH, 1);
        sf.setTimeZone(TimeZone.getTimeZone("UTC"));
        String strt = sf.format(sc.getTime());
        // TimeZone utc = TimeZone.getTimeZone("UTC");
        // sf.setTimeZone(utc);
        // Date d=new Date(sf.format(sc.getTime()));
        System.out.println("Start Date :" + strt);
        SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSzzz");

        Calendar ec = Calendar.getInstance();
        ec.set(Calendar.DAY_OF_MONTH, ec.getActualMaximum(Calendar.DAY_OF_MONTH));
        String end = sf1.format(ec.getTime());
        System.out.println("End Date :" + end);
        // Data =
        // "PUT /oozie/v2/job/0023481-160502160551671-oozie-oozi-C?action=coord-rerun&type="
        // + strt + "::" + end + "&scope=&refresh=false&nocleanup=false";
        if (End.before(new Date()) == true) {

            URL url1 = null;
            try {
                url1 = new URL("http:localhost:11000/oozie/v2/job/0023481-160502160551671-oozie-oozi-C?action=coord-rerun&type=date" + strt + "::" + end + "&scope=&refresh=false&nocleanup=false");
                HttpURLConnection hurl = (HttpURLConnection) url1.openConnection();
                hurl.setRequestMethod("PUT");
                hurl.setDoOutput(true);
                // hurl.setRequestProperty("Content-Type", "application/json");

                // String payload = "";

                // OutputStreamWriter os = new
                // OutputStreamWriter(hurl.getOutputStream());
                // os.write();
                // os.flush();
                // os.close();

            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // connection.setUseCaches(false);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

可以使用以下参数"更改"来更改协调器的某些参数。参数"值"。

oozie job -oozie http://$oozie_path/oozie -change $oozie_coorinator_id -value endtime=$new_timestamp

使用值,您可以传递以下参数:

endtime:协调员作业的结束时间。 并发:协调器作业的并发性。 pausetime:协调员作业的暂停时间。 状态:协调员工作的新状态。

但是,似乎无法修改开始时间。最好的方法是停止当前协调员并使用正确的值再次启动它。

来源:https://oozie.apache.org/docs/4.1.0/DG_CommandLineTool.html#Changing_endtimeconcurrencypausetimestatus_of_a_Coordinator_Job (更改协调器作业的结束时间/并发/暂停时间/状态)