This project has retired. For details please refer to its
Attic page.
001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.oozie.client.rest;
019
020 import java.util.HashSet;
021 import java.util.List;
022 import java.util.Set;
023
024 import org.apache.oozie.BundleJobBean;
025 import org.apache.oozie.CoordinatorActionBean;
026 import org.apache.oozie.CoordinatorJobBean;
027 import org.apache.oozie.client.BulkResponse;
028 import org.json.simple.JSONArray;
029 import org.json.simple.JSONObject;
030
031 /**
032 * Server-side implementation class of the client interface BulkResponse
033 * Declares all the bulk request specific user parameters and handling as JSON object
034 */
035 public class BulkResponseImpl implements BulkResponse, JsonBean {
036 private BundleJobBean bundle;
037 private CoordinatorJobBean coordinator;
038 private CoordinatorActionBean action;
039
040 public static final String BULK_FILTER_BUNDLE_NAME = "bundle";
041 public static final String BULK_FILTER_COORD_NAME = "coordinators";
042 public static final String BULK_FILTER_LEVEL = "filterlevel";
043 public static final String BULK_FILTER_STATUS = "actionstatus";
044 public static final String BULK_FILTER_START_CREATED_EPOCH = "startcreatedtime";
045 public static final String BULK_FILTER_END_CREATED_EPOCH = "endcreatedtime";
046 public static final String BULK_FILTER_START_NOMINAL_EPOCH = "startscheduledtime";
047 public static final String BULK_FILTER_END_NOMINAL_EPOCH = "endscheduledtime";
048 public static final String BULK_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:SS'Z'";
049
050 public static final Set<String> BULK_FILTER_NAMES = new HashSet<String>();
051
052 static {
053
054 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_BUNDLE_NAME);
055 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_COORD_NAME);
056 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_LEVEL);
057 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_STATUS);
058 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_START_CREATED_EPOCH);
059 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_END_CREATED_EPOCH);
060 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_START_NOMINAL_EPOCH);
061 BULK_FILTER_NAMES.add(BulkResponseImpl.BULK_FILTER_END_NOMINAL_EPOCH);
062
063 }
064
065 /**
066 * Construct JSON object using the bulk request object and the associated tags
067 */
068 public JSONObject toJSONObject() {
069 return toJSONObject("GMT");
070 }
071
072 /**
073 * Construct JSON object using the bulk request object and the associated tags
074 */
075 @SuppressWarnings("unchecked")
076 public JSONObject toJSONObject(String timeZoneId) {
077 JSONObject json = new JSONObject();
078
079 json.put(JsonTags.BULK_RESPONSE_BUNDLE, bundle.toJSONObject());
080 json.put(JsonTags.BULK_RESPONSE_COORDINATOR, coordinator.toJSONObject());
081 json.put(JsonTags.BULK_RESPONSE_ACTION, action.toJSONObject());
082
083 json.put(JsonTags.BUNDLE_JOB_NAME, bundle.getAppName());
084 json.put(JsonTags.BUNDLE_JOB_ID, bundle.getId());
085 json.put(JsonTags.BUNDLE_JOB_STATUS, bundle.getStatus().toString());
086
087 json.put(JsonTags.COORDINATOR_JOB_NAME, coordinator.getAppName());
088 json.put(JsonTags.COORDINATOR_JOB_STATUS, coordinator.getStatus().toString());
089
090 json.put(JsonTags.COORDINATOR_ACTION_ID, action.getId());
091 json.put(JsonTags.COORDINATOR_JOB_ID, action.getJobId());
092 json.put(JsonTags.COORDINATOR_ACTION_NUMBER, action.getActionNumber());
093 json.put(JsonTags.COORDINATOR_ACTION_EXTERNALID, action.getExternalId());
094 json.put(JsonTags.COORDINATOR_ACTION_STATUS, action.getStatus().toString());
095 json.put(JsonTags.COORDINATOR_ACTION_EXTERNAL_STATUS, action.getExternalStatus());
096 json.put(JsonTags.COORDINATOR_ACTION_ERROR_CODE, action.getErrorCode());
097 json.put(JsonTags.COORDINATOR_ACTION_ERROR_MESSAGE, action.getErrorMessage());
098 json.put(JsonTags.COORDINATOR_ACTION_CREATED_TIME, action.getCreatedTime().toString());
099 json.put(JsonTags.COORDINATOR_ACTION_NOMINAL_TIME, action.getNominalTime().toString());
100 json.put(JsonTags.COORDINATOR_ACTION_MISSING_DEPS, action.getMissingDependencies());
101
102 return json;
103 }
104
105 /* (non-Javadoc)
106 * @see org.apache.oozie.client.BulkResponse#getBundle()
107 */
108 @Override
109 public BundleJobBean getBundle() {
110 return bundle;
111 }
112
113 /* (non-Javadoc)
114 * @see org.apache.oozie.client.BulkResponse#getCoordinator()
115 */
116 @Override
117 public CoordinatorJobBean getCoordinator() {
118 return coordinator;
119 }
120
121 /* (non-Javadoc)
122 * @see org.apache.oozie.client.BulkResponse#getAction()
123 */
124 @Override
125 public CoordinatorActionBean getAction() {
126 return action;
127 }
128
129 /**
130 * Sets the bundle comprising this bulk response object
131 * @param BundleJobBean
132 */
133 public void setBundle(BundleJobBean bj) {
134 this.bundle = bj;
135 }
136
137 /**
138 * Sets the coordinator comprising this bulk response object
139 * @param CoordinatorJobBean
140 */
141 public void setCoordinator(CoordinatorJobBean cj) {
142 this.coordinator = cj;
143 }
144
145 /**
146 * Sets the coord action comprising this bulk response object
147 * @param CoordinatorActionBean
148 */
149 public void setAction(CoordinatorActionBean ca) {
150 this.action = ca;
151 }
152
153 /**
154 * Convert a nodes list into a JSONArray.
155 *
156 * @param actions nodes list.
157 * @param timeZoneId time zone to use for dates in the JSON array.
158 * @return the corresponding JSON array.
159 */
160 @SuppressWarnings("unchecked")
161 public static JSONArray toJSONArray(List<? extends BulkResponseImpl> responses, String timeZoneId) {
162 JSONArray array = new JSONArray();
163 for (BulkResponseImpl response : responses) {
164 array.add(response.toJSONObject(timeZoneId));
165 }
166 return array;
167 }
168 }