Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
FALCON-1972 Handling cases when Extension service or extension.store.…
…uri is not set in startup properties"

Author: Sowmya Ramesh <sramesh@hortonworks.com>

Reviewers: "Balu Vellanki <balu@apache.org>"

Closes #152 from sowmyaramesh/FALCON-1972
  • Loading branch information
Sowmya Ramesh authored and sowmyaramesh committed May 20, 2016
1 parent fcd066a commit fbd9fbedbfbf9958b03dff47be6888fdc743ec16
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
@@ -35,6 +35,8 @@ public String getName() {

@Override
public void init() throws FalconException {
// Validate if extension store is setup
getExtensionStore();
}

@Override
@@ -29,13 +29,15 @@
import org.apache.falcon.extensions.AbstractExtension;
import org.apache.falcon.extensions.Extension;
import org.apache.falcon.extensions.ExtensionProperties;
import org.apache.falcon.extensions.ExtensionService;
import org.apache.falcon.extensions.store.ExtensionStore;
import org.apache.falcon.resource.APIResult;
import org.apache.falcon.resource.AbstractSchedulableEntityManager;
import org.apache.falcon.resource.EntityList;
import org.apache.falcon.resource.ExtensionInstanceList;
import org.apache.falcon.resource.ExtensionJobList;
import org.apache.falcon.resource.InstancesResult;
import org.apache.falcon.service.Services;
import org.apache.falcon.util.DeploymentUtil;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
@@ -79,7 +81,6 @@ public class ExtensionManager extends AbstractSchedulableEntityManager {
public static final String DESCENDING_SORT_ORDER = "desc";

private Extension extension = new Extension();
private static final ExtensionStore STORE = ExtensionStore.get();
private static final String EXTENSION_RESULTS = "extensions";
private static final String TOTAL_RESULTS = "totalResults";
private static final String README = "README";
@@ -103,6 +104,7 @@ public ExtensionJobList getExtensionJobs(
@DefaultValue("0") @QueryParam("offset") Integer offset,
@QueryParam("numResults") Integer resultsPerPage,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
resultsPerPage = resultsPerPage == null ? getDefaultResultsPerPage() : resultsPerPage;
try {
// get filtered entities
@@ -155,6 +157,7 @@ public ExtensionInstanceList getInstances(
@DefaultValue("0") @QueryParam("offset") final Integer offset,
@QueryParam("numResults") Integer resultsPerPage,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
resultsPerPage = resultsPerPage == null ? getDefaultResultsPerPage() : resultsPerPage;
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
@@ -184,6 +187,7 @@ public ExtensionInstanceList getInstances(
@Produces({MediaType.TEXT_XML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
public APIResult schedule(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
@@ -207,6 +211,7 @@ public APIResult schedule(@PathParam("job-name") String jobName,
@Produces({MediaType.TEXT_XML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
public APIResult suspend(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
@@ -234,6 +239,7 @@ public APIResult suspend(@PathParam("job-name") String jobName,
@Produces({MediaType.TEXT_XML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
public APIResult resume(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
@@ -261,6 +267,7 @@ public APIResult resume(@PathParam("job-name") String jobName,
@Produces({MediaType.TEXT_XML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
public APIResult delete(@PathParam("job-name") String jobName,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = getEntityList("", "", "", TAG_PREFIX_EXTENSION_JOB + jobName, "", doAsUser);
if (entities.isEmpty()) {
@@ -292,6 +299,7 @@ public APIResult submit(
@PathParam("extension-name") String extensionName,
@Context HttpServletRequest request,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = generateEntities(extensionName, request);
for (Entity entity : entities) {
@@ -312,6 +320,7 @@ public APIResult submitAndSchedule(
@PathParam("extension-name") String extensionName,
@Context HttpServletRequest request,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = generateEntities(extensionName, request);
for (Entity entity : entities) {
@@ -335,6 +344,7 @@ public APIResult update(
@PathParam("extension-name") String extensionName,
@Context HttpServletRequest request,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = generateEntities(extensionName, request);
for (Entity entity : entities) {
@@ -355,6 +365,7 @@ public APIResult validate(
@PathParam("extension-name") String extensionName,
@Context HttpServletRequest request,
@DefaultValue("") @QueryParam("doAs") String doAsUser) {
checkIfExtensionServiceIsEnabled();
try {
List<Entity> entities = generateEntities(extensionName, request);
for (Entity entity : entities) {
@@ -373,10 +384,11 @@ public APIResult validate(
@Path("enumerate")
@Produces({MediaType.APPLICATION_JSON})
public Response getExtensions() {
checkIfExtensionServiceIsEnabled();
JSONArray results;

try {
List<String> extensions = STORE.getExtensions();
List<String> extensions = ExtensionStore.get().getExtensions();
results = buildEnumerateResult(extensions);
} catch (StoreAccessException e) {
LOG.error("Failed when accessing extension store.", e);
@@ -401,9 +413,10 @@ public Response getExtensions() {
@Produces(MediaType.TEXT_PLAIN)
public String getExtensionDescription(
@PathParam("extension-name") String extensionName) {
checkIfExtensionServiceIsEnabled();
validateExtensionName(extensionName);
try {
return STORE.getResource(extensionName, README);
return ExtensionStore.get().getResource(extensionName, README);
} catch (Throwable e) {
throw FalconWebException.newAPIException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
@@ -414,9 +427,10 @@ public String getExtensionDescription(
@Produces({MediaType.APPLICATION_JSON})
public String getExtensionDefinition(
@PathParam("extension-name") String extensionName) {
checkIfExtensionServiceIsEnabled();
validateExtensionName(extensionName);
try {
return STORE.getResource(extensionName,
return ExtensionStore.get().getResource(extensionName,
extensionName.toLowerCase() + EXTENSION_PROPERTY_JSON_SUFFIX);
} catch (Throwable e) {
throw FalconWebException.newAPIException(e, Response.Status.INTERNAL_SERVER_ERROR);
@@ -453,7 +467,8 @@ private static JSONArray buildEnumerateResult(final List<String> extensions) thr
}

private static String getShortDescription(final String extensionName) throws FalconException {
String content = STORE.getResource(extensionName, extensionName.toLowerCase() + EXTENSION_PROPERTY_JSON_SUFFIX);
String content = ExtensionStore.get().getResource(extensionName, extensionName.toLowerCase()
+ EXTENSION_PROPERTY_JSON_SUFFIX);
String description;
try {
JSONObject jsonObject = new JSONObject(content);
@@ -535,4 +550,11 @@ private String getJobNameFromTag(String tags) {
}
return tags.substring(nameStart, nameEnd);
}

private static void checkIfExtensionServiceIsEnabled() {
if (!Services.get().isRegistered(ExtensionService.SERVICE_NAME)) {
throw FalconWebException.newAPIException(
ExtensionService.SERVICE_NAME + " is not enabled.", Response.Status.NOT_FOUND);
}
}
}
@@ -42,7 +42,8 @@
org.apache.falcon.notification.service.impl.SchedulerService,\
org.apache.falcon.notification.service.impl.AlarmService,\
org.apache.falcon.notification.service.impl.DataAvailabilityService,\
org.apache.falcon.execution.FalconExecutionService
org.apache.falcon.execution.FalconExecutionService,\
org.apache.falcon.extensions.ExtensionService

##### Falcon Configuration Store Change listeners #####
*.configstore.listeners=org.apache.falcon.entity.v0.EntityGraph,\

0 comments on commit fbd9fbe

Please sign in to comment.