Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
FALCON-1961 Should return error if an extension job doesn't exist for…
… delete/suspend/resume/schedule operations

Author: yzheng-hortonworks <yzheng@hortonworks.com>

Reviewers: "Sowmya Ramesh <sowmya_kr@apache.org>, Balu Vellanki <balu@apache.org>"

Closes #144 from yzheng-hortonworks/FALCON-1961
  • Loading branch information
Ying Zheng authored and sowmyaramesh committed May 18, 2016
1 parent 78bb796 commit 6d73fad44c67b3bb013c37a2939fa00aacd12668
Showing 1 changed file with 28 additions and 0 deletions.
@@ -107,6 +107,9 @@ public ExtensionJobList getExtensionJobs(
try {
// get filtered entities
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_NAME + extensionName, "", doAsUser);
if (entities.isEmpty()) {
return new ExtensionJobList(0);
}

// group entities by extension job name
Map<String, List<Entity>> groupedEntities = groupEntitiesByJob(entities);
@@ -155,6 +158,10 @@ public ExtensionInstanceList getInstances(
resultsPerPage = resultsPerPage == null ? getDefaultResultsPerPage() : resultsPerPage;
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
return new ExtensionInstanceList(0);
}

HashSet<String> fieldSet = new HashSet<>(Arrays.asList(fields.toUpperCase().split(",")));
ExtensionInstanceList instances = new ExtensionInstanceList(entities.size());
for (Entity entity : entities) {
@@ -179,6 +186,11 @@ public APIResult schedule(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
// return failure if the extension job doesn't exist
return new APIResult(APIResult.Status.FAILED, "Extension job " + jobName + " doesn't exist.");
}

for (Entity entity : entities) {
scheduleInternal(entity.getEntityType().name(), entity.getName(), null, null);
}
@@ -197,6 +209,11 @@ public APIResult suspend(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
// return failure if the extension job doesn't exist
return new APIResult(APIResult.Status.FAILED, "Extension job " + jobName + " doesn't exist.");
}

for (Entity entity : entities) {
if (entity.getEntityType().isSchedulable()) {
if (getWorkflowEngine(entity).isActive(entity)) {
@@ -219,6 +236,11 @@ public APIResult resume(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
// return failure if the extension job doesn't exist
return new APIResult(APIResult.Status.FAILED, "Extension job " + jobName + " doesn't exist.");
}

for (Entity entity : entities) {
if (entity.getEntityType().isSchedulable()) {
if (getWorkflowEngine(entity).isSuspended(entity)) {
@@ -241,6 +263,12 @@ public APIResult delete(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
// return failure if the extension job doesn't exist
return new APIResult(APIResult.Status.SUCCEEDED,
"Extension job " + jobName + " doesn't exist. Nothing to delete.");
}

for (Entity entity : entities) {
// TODO(yzheng): need to remember the entity dependency graph for clean ordered removal
canRemove(entity);

0 comments on commit 6d73fad

Please sign in to comment.