@Override public boolean createOrUpdate(StreamViewId viewId, ViewSpecification config) { Lock lock = viewsLock.writeLock(); lock.lock(); try { return views.put(viewId, viewId.getParent(), config) == null; } finally { lock.unlock(); } }
@Override public boolean exists(StreamViewId viewId) { Lock lock = viewsLock.readLock(); lock.lock(); try { return views.contains(viewId, viewId.getParent()); } finally { lock.unlock(); } }
@Override public boolean createOrUpdateView(final StreamViewId viewId, final ViewSpecification spec) throws Exception { final StreamId stream = viewId.getParent(); return streamCoordinatorClient.exclusiveAction( stream, new Callable<Boolean>() { @Override public Boolean call() throws Exception { if (!exists(stream)) { throw new NotFoundException(stream); } return viewAdmin.createOrUpdate(viewId, spec); } }); }
@Override public void delete(StreamViewId viewId) throws NotFoundException { ViewSpecification removed; Lock lock = viewsLock.writeLock(); lock.lock(); try { removed = views.remove(viewId, viewId.getParent()); } finally { lock.unlock(); } if (removed == null) { throw new NotFoundException(viewId); } }
@Override public ViewDetail get(StreamViewId viewId) throws NotFoundException { Lock lock = viewsLock.readLock(); lock.lock(); try { if (!views.containsRow(viewId)) { throw new NotFoundException(viewId); } return new ViewDetail(viewId.getEntityName(), views.get(viewId, viewId.getParent())); } finally { lock.unlock(); } } }
@Override public ViewSpecification getView(StreamViewId viewId) throws Exception { Preconditions.checkArgument(exists(viewId.getParent()), "Stream '%s' does not exist.", viewId.getStream()); return viewAdmin.get(viewId); }
@Override public void deleteView(final StreamViewId viewId) throws Exception { final StreamId stream = viewId.getParent(); streamCoordinatorClient.exclusiveAction( stream, new Callable<Void>() { @Override public Void call() throws Exception { if (!exists(stream)) { throw new StreamNotFoundException(stream); } viewAdmin.delete(viewId); return null; } }); }
@Override public boolean createOrUpdateView(StreamViewId viewId, ViewSpecification spec) throws Exception { Preconditions.checkArgument(exists(viewId.getParent()), "Stream '%s' does not exist.", viewId.getStream()); return viewAdmin.createOrUpdate(viewId, spec); }
@Override public void deleteView(StreamViewId viewId) throws Exception { Preconditions.checkArgument(exists(viewId.getParent()), "Stream '%s' does not exist.", viewId.getStream()); viewAdmin.delete(viewId); }
@Override public boolean createOrUpdateView(StreamViewId viewId, ViewSpecification spec) throws Exception { AuthorizationUtil.ensureAccess(viewId.getParent(), authorizationEnforcer, authenticationContext.getPrincipal()); return delegate.createOrUpdateView(viewId, spec); }
@Override public boolean viewExists(StreamViewId viewId) throws Exception { AuthorizationUtil.ensureAccess(viewId.getParent(), authorizationEnforcer, authenticationContext.getPrincipal()); return delegate.viewExists(viewId); }
@Override public void deleteView(StreamViewId viewId) throws Exception { AuthorizationUtil.ensureAccess(viewId.getParent(), authorizationEnforcer, authenticationContext.getPrincipal()); delegate.deleteView(viewId); }
@Override public ViewSpecification getView(StreamViewId viewId) throws Exception { AuthorizationUtil.ensureAccess(viewId.getParent(), authorizationEnforcer, authenticationContext.getPrincipal()); return delegate.getView(viewId); }
@Override public boolean viewExists(StreamViewId viewId) throws Exception { StreamId stream = viewId.getParent(); if (!exists(stream)) { throw new StreamNotFoundException(stream); } return viewAdmin.exists(viewId); }
@Override public ViewSpecification getView(final StreamViewId viewId) throws Exception { final StreamId stream = viewId.getParent(); if (!exists(stream)) { throw new StreamNotFoundException(stream); } return viewAdmin.get(viewId); }
public void delete(StreamViewId viewId) throws Exception { ViewSpecification spec = store.get(viewId); explore.disableExploreStream(viewId.getParent(), spec.getTableName()); store.delete(viewId); metadataStore.removeMetadata(viewId.toMetadataEntity()); }
public boolean createOrUpdate(StreamViewId viewId, ViewSpecification spec) throws Exception { try { ViewSpecification previousSpec = store.get(viewId); if (spec.getTableName() == null) { // use the previous table name spec = new ViewSpecification(spec.getFormat(), previousSpec.getTableName()); } else if (!spec.getTableName().equals(previousSpec.getTableName())) { throw new IllegalArgumentException(String.format("Cannot change table name for view %s", viewId)); } explore.disableExploreStream(viewId.getParent(), previousSpec.getTableName()); } catch (NotFoundException e) { // pass through } if (spec.getTableName() == null) { spec = new ViewSpecification(spec.getFormat(), naming.getTableName(viewId)); } explore.enableExploreStream(viewId.getParent(), spec.getTableName(), spec.getFormat()); boolean result = store.createOrUpdate(viewId, spec); ViewSystemMetadataWriter systemMetadataWriter = new ViewSystemMetadataWriter(metadataStore, viewId, spec, !result); systemMetadataWriter.write(); return result; }