http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java deleted file mode 100644 index c099cae..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobImpl.java +++ /dev/null @@ -1,323 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.jobs.viewJobs; - -import org.apache.commons.beanutils.PropertyUtils; - -import java.beans.Transient; -import java.lang.reflect.InvocationTargetException; -import java.util.Map; - -/** - * Bean to represent saved query - */ -public class JobImpl implements Job { - private String title = null; - private String queryFile = null; - private String statusDir = null; - private Long dateSubmitted = 0L; - private Long duration = 0L; - private String forcedContent = null; - private String dataBase = null; - private String queryId = null; - - private String status = JOB_STATE_UNKNOWN; - private String statusMessage = null; - private String sqlState = null; - - private String applicationId; - private String dagId; - private String dagName; - - private String sessionTag; - private String referrer; - private String globalSettings; - - private String id = null; - private String owner = null; - - private String logFile; - private String confFile; - - private String hiveQueryId; - - public JobImpl() {} - public JobImpl(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException { - for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) { - try { - PropertyUtils.setProperty(this, entry.getKey(), entry.getValue()); - } catch (NoSuchMethodException e) { - //do nothing, skip - } - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Job)) return false; - - JobImpl job = (JobImpl) o; - - return id != null ? id.equals(job.id) : job.id == null; - - } - - @Override - public int hashCode() { - return id != null ? id.hashCode() : 0; - } - - @Override - @Transient - public String getHiveQueryId() { - return hiveQueryId; - } - - @Override - @Transient - public void setHiveQueryId(String hiveQueryId) { - this.hiveQueryId = hiveQueryId; - } - - @Override - public String getId() { - return id; - } - - @Override - public void setId(String id) { - this.id = id; - } - - @Override - public String getOwner() { - return owner; - } - - @Override - public void setOwner(String owner) { - this.owner = owner; - } - - @Override - public String getTitle() { - return title; - } - - @Override - public void setTitle(String title) { - this.title = title; - } - - @Override - public String getQueryFile() { - return queryFile; - } - - @Override - public void setQueryFile(String queryFile) { - this.queryFile = queryFile; - } - - @Override - public Long getDateSubmitted() { - return dateSubmitted; - } - - @Override - public void setDateSubmitted(Long dateSubmitted) { - this.dateSubmitted = dateSubmitted; - } - - @Override - public Long getDuration() { - return duration; - } - - @Override - public void setDuration(Long duration) { - this.duration = duration; - } - - @Override - public String getStatus() { - return status; - } - - @Override - public void setStatus(String status) { - this.status = status; - } - - @Override - @Transient - public String getForcedContent() { - return forcedContent; - } - - @Override - @Transient - public void setForcedContent(String forcedContent) { - this.forcedContent = forcedContent; - } - - @Override - public String getQueryId() { - return queryId; - } - - @Override - public void setQueryId(String queryId) { - this.queryId = queryId; - } - - @Override - public String getStatusDir() { - return statusDir; - } - - @Override - public void setStatusDir(String statusDir) { - this.statusDir = statusDir; - } - - @Override - public String getDataBase() { - return dataBase; - } - - @Override - public void setDataBase(String dataBase) { - this.dataBase = dataBase; - } - - @Override - public String getLogFile() { - return logFile; - } - - @Override - public void setLogFile(String logFile) { - this.logFile = logFile; - } - - @Override - public String getConfFile() { - return confFile; - } - - @Override - public void setConfFile(String confFile) { - this.confFile = confFile; - } - - @Override - public String getApplicationId() { - return applicationId; - } - - @Override - public void setApplicationId(String applicationId) { - this.applicationId = applicationId; - } - - @Override - public String getDagName() { - return dagName; - } - - @Override - public void setDagName(String dagName) { - this.dagName = dagName; - } - - @Override - public String getDagId() { - return dagId; - } - - @Override - public void setDagId(String dagId) { - this.dagId = dagId; - } - - @Override - public String getSessionTag() { - return sessionTag; - } - - @Override - public void setSessionTag(String sessionTag) { - this.sessionTag = sessionTag; - } - - @Override - @Transient - public String getStatusMessage() { - return statusMessage; - } - - @Override - @Transient - public void setStatusMessage(String statusMessage) { - this.statusMessage = statusMessage; - } - - @Override - public String getSqlState() { - return sqlState; - } - - @Override - public void setSqlState(String sqlState) { - this.sqlState = sqlState; - } - - @Override - public String getReferrer() { - return referrer; - } - - @Override - public void setReferrer(String referrer) { - this.referrer = referrer; - } - - @Override - public String getGlobalSettings() { - return globalSettings; - } - - @Override - public void setGlobalSettings(String globalSettings) { - this.globalSettings = globalSettings; - } - - @Override - public String toString() { - return new StringBuilder("JobImpl{") - .append("id='").append(id) - .append(", owner='").append(owner) - .append(", hiveQueryId='").append(hiveQueryId) - .append(", dagId='").append(dagId) - .append(", queryId='").append(queryId) - .append('}').toString(); - } -}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobInfo.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobInfo.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobInfo.java deleted file mode 100644 index 4162594..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobInfo.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.jobs.viewJobs; - -public class JobInfo { - private String jobId; - private String hiveId; - private String dagId; - private String operationId; - - public JobInfo() { - } - - public JobInfo(String jobId, String hiveId, String dagId, String operationId) { - this.jobId = jobId; - this.hiveId = hiveId; - this.dagId = dagId; - this.operationId = operationId; - } - - public String getJobId() { - return jobId; - } - - public void setJobId(String jobId) { - this.jobId = jobId; - } - - public String getHiveId() { - return hiveId; - } - - public void setHiveId(String hiveId) { - this.hiveId = hiveId; - } - - public String getDagId() { - return dagId; - } - - public void setDagId(String dagId) { - this.dagId = dagId; - } - - public String getOperationId() { - return operationId; - } - - public void setOperationId(String operationId) { - this.operationId = operationId; - } - - @Override - public String toString() { - return new StringBuilder().append("JobInfo{" ) - .append("jobId=").append(jobId) - .append(", hiveId=").append(hiveId) - .append(", dagId=").append(dagId) - .append(", operationId=").append(operationId) - .append('}').toString(); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java deleted file mode 100644 index ed1866e..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/viewJobs/JobResourceManager.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.jobs.viewJobs; - -import org.apache.ambari.view.ViewContext; -import org.apache.ambari.view.hive.client.*; -import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager; -import org.apache.ambari.view.hive.utils.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -/** - * Object that provides CRUD operations for job objects - */ -public class JobResourceManager extends PersonalCRUDResourceManager<Job> { - private final static Logger LOG = - LoggerFactory.getLogger(JobResourceManager.class); - - private IJobControllerFactory jobControllerFactory; - - /** - * Constructor - * @param context View Context instance - */ - public JobResourceManager(SharedObjectsFactory sharedObjectsFactory, ViewContext context) { - super(JobImpl.class, sharedObjectsFactory, context); - jobControllerFactory = sharedObjectsFactory.getJobControllerFactory(); - } - - @Override - public Job create(Job object) { - super.create(object); - JobController jobController = jobControllerFactory.createControllerForJob(object); - - try { - - jobController.afterCreation(); - saveIfModified(jobController); - - } catch (ServiceFormattedException e) { - cleanupAfterErrorAndThrowAgain(object, e); - } - - return object; - } - - public void saveIfModified(JobController jobController) { - if (jobController.isModified()) { - save(jobController.getJobPOJO()); - jobController.clearModified(); - } - } - - - @Override - public Job read(Object id) throws ItemNotFound { - Job job = super.read(id); - JobController jobController = jobControllerFactory.createControllerForJob(job); - jobController.update(); - saveIfModified(jobController); - return job; - } - - @Override - public List<Job> readAll(FilteringStrategy filteringStrategy) { - return super.readAll(filteringStrategy); - } - - @Override - public void delete(Object resourceId) throws ItemNotFound { - super.delete(resourceId); - } - - public JobController readController(Object id) throws ItemNotFound { - Job job = read(id); - return jobControllerFactory.createControllerForJob(job); - } - - public Cursor getJobResultsCursor(Job job) { - try { - JobController jobController = jobControllerFactory.createControllerForJob(job); - return jobController.getResults(); - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException("Job results are expired", null); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java deleted file mode 100644 index c7ed078..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceItem.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.resources; - -import org.apache.ambari.view.hive.persistence.utils.PersonalResource; -import org.apache.commons.beanutils.BeanUtils; - -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.util.Map; - -/** - * Bean to represent file resource - */ -public class FileResourceItem implements Serializable, PersonalResource { - private String name; - private String path; - - private String id; - private String owner; - - public FileResourceItem() {} - public FileResourceItem(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException { - BeanUtils.populate(this, stringObjectMap); - } - - @Override - public String getId() { - return id; - } - - @Override - public void setId(String id) { - this.id = id; - } - - @Override - public String getOwner() { - return owner; - } - - @Override - public void setOwner(String owner) { - this.owner = owner; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java deleted file mode 100644 index 822ae3c..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceManager.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.resources; - -import org.apache.ambari.view.ViewContext; -import org.apache.ambari.view.hive.persistence.IStorageFactory; -import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -/** - * Object that provides CRUD operations for resource objects - */ -public class FileResourceResourceManager extends PersonalCRUDResourceManager<FileResourceItem> { - private final static Logger LOG = - LoggerFactory.getLogger(FileResourceResourceManager.class); - - /** - * Constructor - * @param context View Context instance - */ - public FileResourceResourceManager(IStorageFactory storageFactory, ViewContext context) { - super(FileResourceItem.class, storageFactory, context); - } - - @Override - public FileResourceItem create(FileResourceItem object) { - return super.create(object); - } - - @Override - public FileResourceItem read(Object id) throws ItemNotFound { - return super.read(id); - } - - @Override - public void delete(Object resourceId) throws ItemNotFound { - super.delete(resourceId); - } - - @Override - public List<FileResourceItem> readAll(FilteringStrategy filteringStrategy) { - return super.readAll(filteringStrategy); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java deleted file mode 100644 index a77d10b..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.resources; - -import org.apache.ambari.view.*; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; -import org.apache.ambari.view.hive.utils.SharedObjectsFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import java.lang.reflect.InvocationTargetException; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Resource provider for resource - */ -public class FileResourceResourceProvider implements ResourceProvider<FileResourceItem> { - @Inject - ViewContext context; - - protected FileResourceResourceManager resourceManager = null; - protected final static Logger LOG = - LoggerFactory.getLogger(FileResourceResourceProvider.class); - - protected synchronized FileResourceResourceManager getResourceManager() { - if (resourceManager == null) { - resourceManager = new FileResourceResourceManager(new SharedObjectsFactory(context), context); - } - return resourceManager; - } - - @Override - public FileResourceItem getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - try { - return getResourceManager().read(resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - } - - @Override - public Set<FileResourceItem> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - if (context == null) { - return new HashSet<FileResourceItem>(); - } - return new HashSet<FileResourceItem>(getResourceManager().readAll( - new OnlyOwnersFilteringStrategy(this.context.getUsername()))); - } - - @Override - public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException { - FileResourceItem item = null; - try { - item = new FileResourceItem(stringObjectMap); - } catch (InvocationTargetException e) { - throw new SystemException("error on creating resource", e); - } catch (IllegalAccessException e) { - throw new SystemException("error on creating resource", e); - } - getResourceManager().create(item); - } - - @Override - public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - FileResourceItem item = null; - try { - item = new FileResourceItem(stringObjectMap); - } catch (InvocationTargetException e) { - throw new SystemException("error on updating resource", e); - } catch (IllegalAccessException e) { - throw new SystemException("error on updating resource", e); - } - try { - getResourceManager().update(item, resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - return true; - } - - @Override - public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - try { - getResourceManager().delete(resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - return true; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java deleted file mode 100644 index 412b026..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java +++ /dev/null @@ -1,180 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.resources; - -import org.apache.ambari.view.ViewResourceHandler; -import org.apache.ambari.view.hive.BaseService; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; -import org.apache.ambari.view.hive.utils.NotFoundFormattedException; -import org.apache.ambari.view.hive.utils.ServiceFormattedException; -import org.json.simple.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.util.List; - -/** - * Servlet for Resources - * API: - * GET /:id - * read resource - * POST / - * create new resource - * GET / - * get all resource of current user - */ -public class FileResourceService extends BaseService { - @Inject - ViewResourceHandler handler; - - protected FileResourceResourceManager resourceManager = null; - protected final static Logger LOG = - LoggerFactory.getLogger(FileResourceService.class); - - protected synchronized FileResourceResourceManager getResourceManager() { - if (resourceManager == null) { - resourceManager = new FileResourceResourceManager(getSharedObjectsFactory(), context); - } - return resourceManager; - } - - /** - * Get single item - */ - @GET - @Path("{id}") - @Produces(MediaType.APPLICATION_JSON) - public Response getOne(@PathParam("id") String id) { - try { - FileResourceItem fileResourceItem = getResourceManager().read(id); - JSONObject object = new JSONObject(); - object.put("fileResource", fileResourceItem); - return Response.ok(object).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Delete single item - */ - @DELETE - @Path("{id}") - public Response delete(@PathParam("id") String id) { - try { - getResourceManager().delete(id); - return Response.status(204).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Get all resources - */ - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response getList() { - try { - LOG.debug("Getting all resources"); - List items = getResourceManager().readAll( - new OnlyOwnersFilteringStrategy(this.context.getUsername())); //TODO: move strategy to PersonalCRUDRM - - JSONObject object = new JSONObject(); - object.put("fileResources", items); - return Response.ok(object).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Update item - */ - @PUT - @Path("{id}") - @Consumes(MediaType.APPLICATION_JSON) - public Response update(ResourceRequest request, - @PathParam("id") String id) { - try { - getResourceManager().update(request.fileResource, id); - return Response.status(204).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Create resource - */ - @POST - @Consumes(MediaType.APPLICATION_JSON) - public Response create(ResourceRequest request, @Context HttpServletResponse response, - @Context UriInfo ui) { - try { - getResourceManager().create(request.fileResource); - - FileResourceItem item = null; - - item = getResourceManager().read(request.fileResource.getId()); - - response.setHeader("Location", - String.format("%s/%s", ui.getAbsolutePath().toString(), request.fileResource.getId())); - - JSONObject object = new JSONObject(); - object.put("fileResource", item); - return Response.ok(object).status(201).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Wrapper object for json mapping - */ - public static class ResourceRequest { - public FileResourceItem fileResource; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java deleted file mode 100644 index 25a7748..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQuery.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.savedQueries; - -import org.apache.ambari.view.hive.persistence.utils.PersonalResource; -import org.apache.commons.beanutils.BeanUtils; - -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.util.Map; - -/** - * Bean to represent saved query - */ -public class SavedQuery implements Serializable, PersonalResource { - private String queryFile; - private String dataBase; - private String title; - private String shortQuery; - - private String id; - private String owner; - - public SavedQuery() {} - public SavedQuery(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException { - BeanUtils.populate(this, stringObjectMap); - } - - @Override - public String getId() { - return id; - } - - @Override - public void setId(String id) { - this.id = id; - } - - @Override - public String getOwner() { - return owner; - } - - @Override - public void setOwner(String owner) { - this.owner = owner; - } - - public String getQueryFile() { - return queryFile; - } - - public void setQueryFile(String queryFile) { - this.queryFile = queryFile; - } - - public String getDataBase() { - return dataBase; - } - - public void setDataBase(String dataBase) { - this.dataBase = dataBase; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getShortQuery() { - return shortQuery; - } - - public void setShortQuery(String shortQuery) { - this.shortQuery = shortQuery; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java deleted file mode 100644 index 21a3967..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceManager.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.savedQueries; - -import org.apache.ambari.view.ViewContext; -import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager; -import org.apache.ambari.view.hive.utils.*; -import org.apache.ambari.view.utils.hdfs.HdfsApiException; -import org.apache.ambari.view.utils.hdfs.HdfsUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; - -/** - * Object that provides CRUD operations for query objects - */ -public class SavedQueryResourceManager extends PersonalCRUDResourceManager<SavedQuery> { - private final static Logger LOG = - LoggerFactory.getLogger(SavedQueryResourceManager.class); - - private SharedObjectsFactory sharedObjectsFactory; - - /** - * Constructor - * @param context View Context instance - */ - public SavedQueryResourceManager(ViewContext context, SharedObjectsFactory sharedObjectsFactory) { - super(SavedQuery.class, sharedObjectsFactory, context); - this.sharedObjectsFactory = sharedObjectsFactory; - } - - @Override - public SavedQuery create(SavedQuery object) { - object = super.create(object); - try { - - if (object.getQueryFile() == null || object.getQueryFile().isEmpty()) { - createDefaultQueryFile(object); - } - - } catch (ServiceFormattedException e) { - cleanupAfterErrorAndThrowAgain(object, e); - } - return object; - } - - private void createDefaultQueryFile(SavedQuery object) { - String userScriptsPath = context.getProperties().get("scripts.dir"); - if (userScriptsPath == null) { - String msg = "scripts.dir is not configured!"; - LOG.error(msg); - throw new MisconfigurationFormattedException("scripts.dir"); - } - - String normalizedName = String.format("hive-query-%s", object.getId()); - String timestamp = new SimpleDateFormat("yyyy-MM-dd_hh-mm").format(new Date()); - String baseFileName = String.format(userScriptsPath + - "/%s-%s", normalizedName, timestamp); - - String newFilePath = null; - try { - newFilePath = HdfsUtil.findUnallocatedFileName(sharedObjectsFactory.getHdfsApi(), baseFileName, ".hql"); - HdfsUtil.putStringToFile(sharedObjectsFactory.getHdfsApi(), newFilePath, ""); - } catch (HdfsApiException e) { - throw new ServiceFormattedException(e); - } - - object.setQueryFile(newFilePath); - storageFactory.getStorage().store(SavedQuery.class, object); - } - - @Override - public SavedQuery read(Object id) throws ItemNotFound { - SavedQuery savedQuery = super.read(id); - fillShortQueryField(savedQuery); - return savedQuery; - } - - private void fillShortQueryField(SavedQuery savedQuery) { - if (savedQuery.getQueryFile() != null) { - FilePaginator paginator = new FilePaginator(savedQuery.getQueryFile(), sharedObjectsFactory.getHdfsApi()); - String query = null; - try { - query = paginator.readPage(0); - } catch (IOException e) { - LOG.error("Can't read query file " + savedQuery.getQueryFile()); - return; - } catch (InterruptedException e) { - LOG.error("Can't read query file " + savedQuery.getQueryFile()); - return; - } - savedQuery.setShortQuery(makeShortQuery(query)); - } - storageFactory.getStorage().store(SavedQuery.class, savedQuery); - } - - private void emptyShortQueryField(SavedQuery query) { - query.setShortQuery(""); - storageFactory.getStorage().store(SavedQuery.class, query); - } - - /** - * Generate short preview of query. - * Remove SET settings like "set hive.execution.engine=tez;" from beginning - * and trim to 42 symbols. - * @param query full query - * @return shortened query - */ - protected static String makeShortQuery(String query) { - query = query.replaceAll("(?i)set\\s+[\\w\\-.]+(\\s*)=(\\s*)[\\w\\-.]+(\\s*);", ""); - query = query.trim(); - return query.substring(0, (query.length() > 42)?42:query.length()); - } - - @Override - public SavedQuery update(SavedQuery newObject, String id) throws ItemNotFound { - SavedQuery savedQuery = super.update(newObject, id); - // Emptying short query so that in next read, this gets updated with proper value - // from the queryFile - emptyShortQueryField(savedQuery); - return savedQuery; - } - - @Override - public List<SavedQuery> readAll(FilteringStrategy filteringStrategy) { - List<SavedQuery> queries = super.readAll(filteringStrategy); - for(SavedQuery query : queries) { - String shortQuery = query.getShortQuery(); - if(shortQuery == null || shortQuery.isEmpty()) { - fillShortQueryField(query); - } - } - return queries; - } - - @Override - public void delete(Object resourceId) throws ItemNotFound { - super.delete(resourceId); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java deleted file mode 100644 index 5a8c2fd..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.savedQueries; - -import org.apache.ambari.view.*; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; -import org.apache.ambari.view.hive.utils.SharedObjectsFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import java.lang.reflect.InvocationTargetException; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Resource provider for SavedQuery - */ -public class SavedQueryResourceProvider implements ResourceProvider<SavedQuery> { - @Inject - ViewContext context; - - protected final static Logger LOG = - LoggerFactory.getLogger(SavedQueryResourceProvider.class); - private SharedObjectsFactory sharedObjectsFactory; - - public SharedObjectsFactory getSharedObjectsFactory() { - if (sharedObjectsFactory == null) - sharedObjectsFactory = new SharedObjectsFactory(context); - return sharedObjectsFactory; - } - - protected synchronized SavedQueryResourceManager getResourceManager() { - return getSharedObjectsFactory().getSavedQueryResourceManager(); - } - - @Override - public SavedQuery getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - try { - return getResourceManager().read(resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - } - - @Override - public Set<SavedQuery> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - if (context == null) { - return new HashSet<SavedQuery>(); - } - return new HashSet<SavedQuery>(getResourceManager().readAll( - new OnlyOwnersFilteringStrategy(this.context.getUsername()))); - } - - @Override - public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException { - SavedQuery item = null; - try { - item = new SavedQuery(stringObjectMap); - } catch (InvocationTargetException e) { - throw new SystemException("error on creating resource", e); - } catch (IllegalAccessException e) { - throw new SystemException("error on creating resource", e); - } - getResourceManager().create(item); - } - - @Override - public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - SavedQuery item = null; - try { - item = new SavedQuery(stringObjectMap); - } catch (InvocationTargetException e) { - throw new SystemException("error on updating resource", e); - } catch (IllegalAccessException e) { - throw new SystemException("error on updating resource", e); - } - try { - getResourceManager().update(item, resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - return true; - } - - @Override - public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - try { - getResourceManager().delete(resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - return true; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java deleted file mode 100644 index 4a5872c..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.savedQueries; - -import org.apache.ambari.view.ViewResourceHandler; -import org.apache.ambari.view.hive.BaseService; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; -import org.apache.ambari.view.hive.utils.NotFoundFormattedException; -import org.apache.ambari.view.hive.utils.ServiceFormattedException; -import org.apache.ambari.view.utils.hdfs.HdfsApi; -import org.apache.ambari.view.utils.hdfs.HdfsUtil; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.StreamingOutput; -import javax.ws.rs.core.UriInfo; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.List; - -/** - * Servlet for queries - * API: - * GET /:id - * read SavedQuery - * POST / - * create new SavedQuery - * Required: title, queryFile - * GET / - * get all SavedQueries of current user - */ -public class SavedQueryService extends BaseService { - @Inject - ViewResourceHandler handler; - - protected SavedQueryResourceManager resourceManager = null; - protected final static Logger LOG = - LoggerFactory.getLogger(SavedQueryService.class); - - protected synchronized SavedQueryResourceManager getResourceManager() { - return getSharedObjectsFactory().getSavedQueryResourceManager(); - } - - protected void setResourceManager(SavedQueryResourceManager resourceManager) { - this.resourceManager = resourceManager; - } - - /** - * Get single item - */ - @GET - @Path("{queryId}") - @Produces(MediaType.APPLICATION_JSON) - public Response getOne(@PathParam("queryId") String queryId, - @QueryParam("op") String operation) { - try { - final SavedQuery savedQuery = getResourceManager().read(queryId); - if(operation.equals("download")) { - StreamingOutput stream = new StreamingOutput() { - @Override - public void write(OutputStream os) throws IOException, WebApplicationException { - Writer writer = new BufferedWriter(new OutputStreamWriter(os)); - try { - BufferedReader br=new BufferedReader(new InputStreamReader(getSharedObjectsFactory().getHdfsApi().open(savedQuery.getQueryFile()))); - String line; - line=br.readLine(); - while (line != null){ - writer.write(line+"\n"); - line = br.readLine(); - } - writer.flush(); - } catch (InterruptedException e) { - e.printStackTrace(); - } finally { - writer.close(); - } - } - }; - return Response.ok(stream). - type(MediaType.TEXT_PLAIN). - build(); - } - else { - JSONObject object = new JSONObject(); - object.put("savedQuery", savedQuery); - return Response.ok(object).build(); - } - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Delete single item - */ - @DELETE - @Path("{queryId}") - public Response delete(@PathParam("queryId") String queryId) { - try { - getResourceManager().delete(queryId); - return Response.status(204).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Get all SavedQueries - */ - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response getList() { - try { - LOG.debug("Getting all SavedQuery"); - List allSavedQueries = getResourceManager().readAll( - new OnlyOwnersFilteringStrategy(this.context.getUsername())); //TODO: move strategy to PersonalCRUDRM - - JSONObject object = new JSONObject(); - object.put("savedQueries", allSavedQueries); - return Response.ok(object).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Update item - */ - @PUT - @Path("{queryId}") - @Consumes(MediaType.APPLICATION_JSON) - public Response update(SavedQueryRequest request, - @PathParam("queryId") String queryId) { - try { - getResourceManager().update(request.savedQuery, queryId); - return Response.status(204).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Create savedQuery - */ - @POST - @Consumes(MediaType.APPLICATION_JSON) - public Response create(SavedQueryRequest request, @Context HttpServletResponse response, - @Context UriInfo ui) { - try { - getResourceManager().create(request.savedQuery); - - SavedQuery item = null; - - item = getResourceManager().read(request.savedQuery.getId()); - - response.setHeader("Location", - String.format("%s/%s", ui.getAbsolutePath().toString(), request.savedQuery.getId())); - - JSONObject object = new JSONObject(); - object.put("savedQuery", item); - return Response.ok(object).status(201).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Get default settings for query - */ - @GET - @Path("defaultSettings") - @Produces(MediaType.APPLICATION_JSON) - public Response getDefaultSettings() { - try { - String defaultsFile = context.getProperties().get("scripts.settings.defaults-file"); - HdfsApi hdfsApi = getSharedObjectsFactory().getHdfsApi(); - - String defaults = "{\"settings\": {}}"; - if (hdfsApi.exists(defaultsFile)) { - defaults = HdfsUtil.readFile(hdfsApi, defaultsFile); - } - return Response.ok(JSONValue.parse(defaults)).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Set default settings for query (overwrites if present) - */ - @POST - @Path("defaultSettings") - @Consumes(MediaType.APPLICATION_JSON) - public Response setDefaultSettings(JSONObject settings) { - try { - String defaultsFile = context.getProperties().get("scripts.settings.defaults-file"); - HdfsApi hdfsApi = getSharedObjectsFactory().getHdfsApi(); - - HdfsUtil.putStringToFile(hdfsApi, defaultsFile, - settings.toString()); - String defaults = HdfsUtil.readFile(hdfsApi, defaultsFile); - return Response.ok(JSONValue.parse(defaults)).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Wrapper object for json mapping - */ - public static class SavedQueryRequest { - public SavedQuery savedQuery; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java deleted file mode 100644 index 77c37b5..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDF.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.udfs; - -import org.apache.ambari.view.hive.persistence.utils.PersonalResource; -import org.apache.commons.beanutils.BeanUtils; - -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.util.Map; - -/** - * Bean to represent UDF - */ -public class UDF implements Serializable, PersonalResource { - private String name; - private String classname; - private String fileResource; - - private String id; - private String owner; - - public UDF() {} - public UDF(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException { - BeanUtils.populate(this, stringObjectMap); - } - - @Override - public String getId() { - return id; - } - - @Override - public void setId(String id) { - this.id = id; - } - - @Override - public String getOwner() { - return owner; - } - - @Override - public void setOwner(String owner) { - this.owner = owner; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getClassname() { - return classname; - } - - public void setClassname(String classname) { - this.classname = classname; - } - - public String getFileResource() { - return fileResource; - } - - public void setFileResource(String fileResource) { - this.fileResource = fileResource; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java deleted file mode 100644 index 98a21b3..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceManager.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.udfs; - -import org.apache.ambari.view.ViewContext; -import org.apache.ambari.view.hive.persistence.IStorageFactory; -import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.resources.PersonalCRUDResourceManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -/** - * Object that provides CRUD operations for udf objects - */ -public class UDFResourceManager extends PersonalCRUDResourceManager<UDF> { - private final static Logger LOG = - LoggerFactory.getLogger(UDFResourceManager.class); - - /** - * Constructor - * @param context View Context instance - */ - public UDFResourceManager(IStorageFactory storageFactory, ViewContext context) { - super(UDF.class, storageFactory, context); - } - - @Override - public UDF read(Object id) throws ItemNotFound { - return super.read(id); - } - - @Override - public List<UDF> readAll(FilteringStrategy filteringStrategy) { - return super.readAll(filteringStrategy); - } - - @Override - public UDF create(UDF object) { - return super.create(object); - } - - @Override - public void delete(Object resourceId) throws ItemNotFound { - super.delete(resourceId); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java deleted file mode 100644 index ba83b03..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.udfs; - -import org.apache.ambari.view.*; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; -import org.apache.ambari.view.hive.utils.SharedObjectsFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import java.lang.reflect.InvocationTargetException; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Resource provider for udf - */ -public class UDFResourceProvider implements ResourceProvider<UDF> { - @Inject - ViewContext context; - - protected UDFResourceManager resourceManager = null; - protected final static Logger LOG = - LoggerFactory.getLogger(UDFResourceProvider.class); - - - protected synchronized UDFResourceManager getResourceManager() { - if (resourceManager == null) { - resourceManager = new UDFResourceManager(new SharedObjectsFactory(context), context); - } - return resourceManager; - } - - @Override - public UDF getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - try { - return getResourceManager().read(resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - } - - @Override - public Set<UDF> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - if (context == null) { - return new HashSet<UDF>(); - } - return new HashSet<UDF>(getResourceManager().readAll( - new OnlyOwnersFilteringStrategy(this.context.getUsername()))); - } - - @Override - public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException { - UDF item = null; - try { - item = new UDF(stringObjectMap); - } catch (InvocationTargetException e) { - throw new SystemException("error on creating resource", e); - } catch (IllegalAccessException e) { - throw new SystemException("error on creating resource", e); - } - getResourceManager().create(item); - } - - @Override - public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - UDF item = null; - try { - item = new UDF(stringObjectMap); - } catch (InvocationTargetException e) { - throw new SystemException("error on updating resource", e); - } catch (IllegalAccessException e) { - throw new SystemException("error on updating resource", e); - } - try { - getResourceManager().update(item, resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - return true; - } - - @Override - public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { - try { - getResourceManager().delete(resourceId); - } catch (ItemNotFound itemNotFound) { - throw new NoSuchResourceException(resourceId); - } - return true; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java deleted file mode 100644 index 8082e00..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.ambari.view.hive.resources.udfs; - -import org.apache.ambari.view.ViewResourceHandler; -import org.apache.ambari.view.hive.BaseService; -import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; -import org.apache.ambari.view.hive.resources.resources.FileResourceResourceManager; -import org.apache.ambari.view.hive.utils.NotFoundFormattedException; -import org.apache.ambari.view.hive.utils.ServiceFormattedException; -import org.json.simple.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.util.List; - -/** - * Servlet for UDFs - * API: - * GET /:id - * read udf - * POST / - * create new udf - * GET / - * get all udf of current user - */ -public class UDFService extends BaseService { - @Inject - ViewResourceHandler handler; - - protected UDFResourceManager resourceManager = null; - protected FileResourceResourceManager fileResourceResourceManager = null; - protected final static Logger LOG = - LoggerFactory.getLogger(UDFService.class); - - protected synchronized UDFResourceManager getResourceManager() { - if (resourceManager == null) { - resourceManager = new UDFResourceManager(getSharedObjectsFactory(), context); - } - return resourceManager; - } - - protected synchronized FileResourceResourceManager getFileResourceResourceManager() { - if (fileResourceResourceManager == null) { - fileResourceResourceManager = new FileResourceResourceManager(getSharedObjectsFactory(), context); - } - return fileResourceResourceManager; - } - - /** - * Get single item - */ - @GET - @Path("{id}") - @Produces(MediaType.APPLICATION_JSON) - public Response getOne(@PathParam("id") String id) { - try { - UDF udf = getResourceManager().read(id); - JSONObject object = new JSONObject(); - object.put("udf", udf); - return Response.ok(object).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Delete single item - */ - @DELETE - @Path("{id}") - public Response delete(@PathParam("id") String id) { - try { - getResourceManager().delete(id); - return Response.status(204).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Get all UDFs - */ - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response getList() { - try { - LOG.debug("Getting all udf"); - List items = getResourceManager().readAll( - new OnlyOwnersFilteringStrategy(this.context.getUsername())); //TODO: move strategy to PersonalCRUDRM - - JSONObject object = new JSONObject(); - object.put("udfs", items); - return Response.ok(object).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Update item - */ - @PUT - @Path("{id}") - @Consumes(MediaType.APPLICATION_JSON) - public Response update(UDFRequest request, - @PathParam("id") String id) { - try { - if (request.udf.getFileResource() != null) - getFileResourceResourceManager().read(request.udf.getFileResource()); - getResourceManager().update(request.udf, id); - return Response.status(204).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Create udf - */ - @POST - @Consumes(MediaType.APPLICATION_JSON) - public Response create(UDFRequest request, @Context HttpServletResponse response, - @Context UriInfo ui) { - try { - if (request.udf.getFileResource() != null) - getFileResourceResourceManager().read(request.udf.getFileResource()); - getResourceManager().create(request.udf); - - UDF item = null; - - item = getResourceManager().read(request.udf.getId()); - - response.setHeader("Location", - String.format("%s/%s", ui.getAbsolutePath().toString(), request.udf.getId())); - - JSONObject object = new JSONObject(); - object.put("udf", item); - return Response.ok(object).status(201).build(); - } catch (WebApplicationException ex) { - throw ex; - } catch (ItemNotFound itemNotFound) { - throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); - } catch (Exception ex) { - throw new ServiceFormattedException(ex.getMessage(), ex); - } - } - - /** - * Wrapper object for json mapping - */ - public static class UDFRequest { - public UDF udf; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/CSVParams.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/CSVParams.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/CSVParams.java deleted file mode 100644 index 355ed6a..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/CSVParams.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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 org.apache.ambari.view.hive.resources.uploads; - -import java.io.Serializable; - -public class CSVParams implements Serializable { - - public static final char DEFAULT_DELIMITER_CHAR = ','; - public static final char DEFAULT_ESCAPE_CHAR = '\\'; - public static final char DEFAULT_QUOTE_CHAR = '"'; - - private Character csvDelimiter; - private Character csvEscape; - private Character csvQuote; - - public CSVParams() { - } - - public CSVParams(Character csvDelimiter, Character csvQuote, Character csvEscape) { - this.csvDelimiter = csvDelimiter; - this.csvQuote = csvQuote; - this.csvEscape = csvEscape; - } - - public Character getCsvDelimiter() { - return csvDelimiter; - } - - public void setCsvDelimiter(Character csvDelimiter) { - this.csvDelimiter = csvDelimiter; - } - - public Character getCsvEscape() { - return csvEscape; - } - - public void setCsvEscape(Character csvEscape) { - this.csvEscape = csvEscape; - } - - public Character getCsvQuote() { - return csvQuote; - } - - public void setCsvQuote(Character csvQuote) { - this.csvQuote = csvQuote; - } - - @Override - public String toString() { - return "CSVParams{" + - "csvDelimiter='" + csvDelimiter + '\'' + - ", csvEscape='" + csvEscape + '\'' + - ", csvQuote='" + csvQuote + '\'' + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/ColumnDescriptionImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/ColumnDescriptionImpl.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/ColumnDescriptionImpl.java deleted file mode 100644 index 229b7ed..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/ColumnDescriptionImpl.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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 org.apache.ambari.view.hive.resources.uploads; - -import org.apache.ambari.view.hive.client.ColumnDescription; - -import java.io.Serializable; - -/** - * implementation of ColumnDescription which also includes scale and precision. - */ -public class ColumnDescriptionImpl implements ColumnDescription, Serializable { - private String name; - private String type; - private int position; - /** - * can be null - */ - private Integer precision; - /** - * can be null - */ - private Integer scale; - - public ColumnDescriptionImpl() { - } - - public ColumnDescriptionImpl(String name, String type, int position) { - this.name = name; - this.type = type; - this.position = position; - } - - public ColumnDescriptionImpl(String name, String type, int position, int precision) { - this.name = name; - this.type = type; - this.position = position; - this.precision = precision; - } - - public ColumnDescriptionImpl(String name, String type, int position, int precision, int scale) { - this.name = name; - this.type = type; - this.position = position; - this.precision = precision; - this.scale = scale; - } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(String name) { - this.name = name; - } - - @Override - public String getType() { - return type; - } - - @Override - public void setType(String type) { - this.type = type; - } - - @Override - public int getPosition() { - return this.position; - } - - @Override - public void setPosition(int position) { - this.position = position; - } - - public Integer getPrecision() { - return precision; - } - - public Integer getScale() { - return scale; - } - - public void setPrecision(Integer precision) { - this.precision = precision; - } - - public void setScale(Integer scale) { - this.scale = scale; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ColumnDescriptionImpl that = (ColumnDescriptionImpl) o; - - if (position != that.position) return false; - if (!name.equals(that.name)) return false; - return type.equals(that.type); - - } - - @Override - public int hashCode() { - int result = name.hashCode(); - result = 31 * result + type.hashCode(); - result = 31 * result + position; - return result; - } - - @Override - public String toString() { - return new StringBuilder().append("ColumnDescriptionImpl[") - .append("name : ").append(name) - .append(", type : " + type) - .append(", position : " + position) - .append(", precision : " + precision) - .append(", scale : " + scale) - .append("]").toString(); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/HiveFileType.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/HiveFileType.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/HiveFileType.java deleted file mode 100644 index 6cc1d46..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/HiveFileType.java +++ /dev/null @@ -1,30 +0,0 @@ - -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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 org.apache.ambari.view.hive.resources.uploads; - -public enum HiveFileType { - SEQUENCEFILE, - TEXTFILE, - RCFILE, - ORC, - PARQUET, - AVRO, - INPUTFORMAT; -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableDataReader.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableDataReader.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableDataReader.java deleted file mode 100644 index 7725719..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableDataReader.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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 org.apache.ambari.view.hive.resources.uploads; - -import com.opencsv.CSVWriter; -import org.apache.ambari.view.hive.client.ColumnDescription; -import org.apache.ambari.view.hive.client.Row; -import org.apache.commons.codec.binary.Hex; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.Iterator; -import java.util.List; - -/** - * Takes row iterator as input. - * iterate over rows and creates a CSV formated stream separating rows by endline "\n" - * Note : column values should not contain "\n". - */ -public class TableDataReader extends Reader { - - private static final int CAPACITY = 1024; - private final List<ColumnDescriptionImpl> header; - private StringReader stringReader = new StringReader(""); - - private Iterator<Row> iterator; - private boolean encode = false; - public static final char CSV_DELIMITER = '\001'; - - public TableDataReader(Iterator<Row> rowIterator, List<ColumnDescriptionImpl> header, boolean encode) { - this.iterator = rowIterator; - this.encode = encode; - this.header = header; - } - - @Override - public int read(char[] cbuf, int off, int len) throws IOException { - - int totalLen = len; - int count = 0; - do { - int n = stringReader.read(cbuf, off, len); - - if (n != -1) { - // n were read - len = len - n; // len more to be read - off = off + n; // off now shifted to n more - count += n; - } - - if (count == totalLen) return count; // all totalLen characters were read - - if (iterator.hasNext()) { // keep reading as long as we keep getting rows - StringWriter stringWriter = new StringWriter(CAPACITY); - CSVWriter csvPrinter = new CSVWriter(stringWriter,CSV_DELIMITER); - Row row = iterator.next(); - // encode values so that \n and \r are overridden - Object[] columnValues = row.getRow(); - String[] columns = new String[columnValues.length]; - - for(int i = 0; i < columnValues.length; i++){ - String type = header.get(i).getType(); - if(this.encode && - ( - ColumnDescription.DataTypes.STRING.toString().equals(type) - || ColumnDescription.DataTypes.VARCHAR.toString().equals(type) - || ColumnDescription.DataTypes.CHAR.toString().equals(type) - ) - ){ - columns[i] = Hex.encodeHexString(((String)columnValues[i]).getBytes()); //default charset - }else { - columns[i] = (String) columnValues[i]; - } - } - - csvPrinter.writeNext(columns,false); - stringReader.close(); // close the old string reader - stringReader = new StringReader(stringWriter.getBuffer().toString()); - csvPrinter.close(); - stringWriter.close(); - } else { - return count == 0 ? -1 : count; - } - } while (count < totalLen); - - return count; - } - - @Override - public void close() throws IOException { - - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e423a65e/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableInput.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableInput.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableInput.java deleted file mode 100644 index 1d5adf4..0000000 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/uploads/TableInput.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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 org.apache.ambari.view.hive.resources.uploads; - -import org.apache.ambari.view.hive.resources.uploads.query.TableInfo; - -/** - * used as input in REST call - */ -class TableInput extends TableInfo { - public Boolean isFirstRowHeader = Boolean.FALSE; - - public TableInput() { - } - - public Boolean getIsFirstRowHeader() { - return isFirstRowHeader; - } - - public void setIsFirstRowHeader(Boolean isFirstRowHeader) { - this.isFirstRowHeader = isFirstRowHeader; - } - - public void validate(){ - if( null == this.getHiveFileType()){ - throw new IllegalArgumentException("fileType parameter cannot be null."); - } - if( null == this.getTableName()){ - throw new IllegalArgumentException("tableName parameter cannot be null."); - } - if( null == this.getDatabaseName()){ - throw new IllegalArgumentException("databaseName parameter cannot be null."); - } - } -}