Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017 LinkedIn Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package azkaban.executor;
import azkaban.db.DatabaseOperator;
import azkaban.db.EncodingType;
import azkaban.db.SQLTransaction;
import azkaban.utils.GZIPUtils;
import azkaban.utils.JSONUtils;
import azkaban.utils.Pair;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.log4j.Logger;
@Singleton
public class ExecutionFlowDao {
private static final Logger logger = Logger.getLogger(ExecutionFlowDao.class);
private final DatabaseOperator dbOperator;
@Inject
public ExecutionFlowDao(final DatabaseOperator dbOperator) {
this.dbOperator = dbOperator;
}
public synchronized void uploadExecutableFlow(final ExecutableFlow flow)
throws ExecutorManagerException {
final String INSERT_EXECUTABLE_FLOW = "INSERT INTO execution_flows "
+ "(project_id, flow_id, version, status, submit_time, submit_user, update_time) "
+ "values (?,?,?,?,?,?,?)";
final long submitTime = System.currentTimeMillis();
flow.setStatus(Status.PREPARING);
/**
* Why we need a transaction to get last insert ID?
* Because "SELECT LAST_INSERT_ID()" needs to have the same connection
* as inserting the new entry.
* See https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_last-insert-id
*/
final SQLTransaction insertAndGetLastID = transOperator -> {
transOperator.update(INSERT_EXECUTABLE_FLOW, flow.getProjectId(),
flow.getFlowId(), flow.getVersion(), Status.PREPARING.getNumVal(),
submitTime, flow.getSubmitUser(), submitTime);
transOperator.getConnection().commit();
return transOperator.getLastInsertId();
};
try {
final long id = this.dbOperator.transaction(insertAndGetLastID);
logger.info("Flow given " + flow.getFlowId() + " given id " + id);
flow.setExecutionId((int) id);
updateExecutableFlow(flow);
} catch (final SQLException e) {
throw new ExecutorManagerException("Error creating execution.", e);
}
}
List fetchFlowHistory(final int skip, final int num)
throws ExecutorManagerException {
try {
return this.dbOperator.query(FetchExecutableFlows.FETCH_ALL_EXECUTABLE_FLOW_HISTORY,
new FetchExecutableFlows(), skip, num);
} catch (final SQLException e) {
throw new ExecutorManagerException("Error fetching flow History", e);
}
}
List fetchFlowHistory(final int projectId, final String flowId,
final int skip, final int num)
throws ExecutorManagerException {
try {
return this.dbOperator.query(FetchExecutableFlows.FETCH_EXECUTABLE_FLOW_HISTORY,
new FetchExecutableFlows(), projectId, flowId, skip, num);
} catch (final SQLException e) {
throw new ExecutorManagerException("Error fetching flow history", e);
}
}
public List> fetchQueuedFlows()
throws ExecutorManagerException {
try {
return this.dbOperator.query(FetchQueuedExecutableFlows.FETCH_QUEUED_EXECUTABLE_FLOW,
new FetchQueuedExecutableFlows());
} catch (final SQLException e) {
throw new ExecutorManagerException("Error fetching active flows", e);
}
}
/**
* fetch flow execution history with specified {@code projectId}, {@code flowId} and flow start
* time >= {@code startTime}
*
* @return the list of flows meeting the specified criteria
*/
public List fetchFlowHistory(final int projectId, final String flowId, final
long startTime) throws ExecutorManagerException {
try {
return this.dbOperator.query(FetchExecutableFlows.FETCH_EXECUTABLE_FLOW_BY_START_TIME,
new FetchExecutableFlows(), projectId, flowId, startTime);
} catch (final SQLException e) {
throw new ExecutorManagerException("Error fetching historic flows", e);
}
}
List fetchFlowHistory(final int projectId, final String flowId,
final int skip, final int num, final Status status)
throws ExecutorManagerException {
try {
return this.dbOperator.query(FetchExecutableFlows.FETCH_EXECUTABLE_FLOW_BY_STATUS,
new FetchExecutableFlows(), projectId, flowId, status.getNumVal(), skip, num);
} catch (final SQLException e) {
throw new ExecutorManagerException("Error fetching active flows", e);
}
}
List fetchRecentlyFinishedFlows(final Duration maxAge)
throws ExecutorManagerException {
try {
return this.dbOperator.query(FetchRecentlyFinishedFlows.FETCH_RECENTLY_FINISHED_FLOW,
new FetchRecentlyFinishedFlows(), System.currentTimeMillis() - maxAge.toMillis(),
Status.SUCCEEDED.getNumVal(), Status.KILLED.getNumVal(),
Status.FAILED.getNumVal());
} catch (final SQLException e) {
throw new ExecutorManagerException("Error fetching recently finished flows", e);
}
}
List fetchFlowHistory(final String projContain, final String flowContains,
final String userNameContains, final int status,
final long startTime, final long endTime,
final int skip, final int num)
throws ExecutorManagerException {
String query = FetchExecutableFlows.FETCH_BASE_EXECUTABLE_FLOW_QUERY;
final List