/** * Copyright 2017 StreamSets Inc. * * Licensed under 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 com.streamsets.datacollector.execution; import com.streamsets.datacollector.callback.CallbackInfo; import com.streamsets.datacollector.callback.CallbackObjectType; import com.streamsets.datacollector.execution.alerts.AlertInfo; import com.streamsets.datacollector.execution.runner.common.PipelineRunnerException; import com.streamsets.datacollector.execution.runner.common.SampledRecord; import com.streamsets.datacollector.restapi.bean.UserJson; import com.streamsets.datacollector.runner.PipelineRuntimeException; import com.streamsets.datacollector.store.AclStoreTask; import com.streamsets.datacollector.store.PipelineStoreException; import com.streamsets.datacollector.util.PipelineException; import com.streamsets.pipeline.api.Record; import com.streamsets.pipeline.api.StageException; import com.streamsets.pipeline.api.impl.ErrorMessage; import java.util.Collection; import java.util.List; import java.util.Map; public class AclRunner implements Runner { private final Runner runner; private final AclStoreTask aclStore; private final UserJson currentUser; public AclRunner(Runner runner, AclStoreTask aclStore, UserJson currentUser) { this.runner = runner; this.aclStore = aclStore; this.currentUser = currentUser; } @Override public String getName() { return runner.getName(); } @Override public String getRev() { return runner.getRev(); } @Override public void resetOffset(String user) throws PipelineException { aclStore.validateExecutePermission(this.getName(), currentUser); runner.resetOffset(user); } @Override public Map<String, String> getCommittedOffsets() throws PipelineException { aclStore.validateExecutePermission(this.getName(), currentUser); return runner.getCommittedOffsets(); } @Override public PipelineState getState() throws PipelineStoreException { return runner.getState(); } @Override public void prepareForDataCollectorStart(String user) throws PipelineStoreException, PipelineRunnerException { runner.prepareForDataCollectorStart(user); } @Override public void onDataCollectorStart(String user) throws PipelineException, StageException { runner.onDataCollectorStart(user); } @Override public void onDataCollectorStop(String user) throws PipelineStoreException, PipelineRunnerException, PipelineRuntimeException { runner.onDataCollectorStop(user); } @Override public void stop(String user) throws PipelineException { aclStore.validateExecutePermission(this.getName(), currentUser); runner.stop(user); } @Override public void forceQuit(String user) throws PipelineException { aclStore.validateExecutePermission(this.getName(), currentUser); runner.forceQuit(user); } @Override public void prepareForStart(String user) throws PipelineStoreException, PipelineRunnerException { runner.prepareForStart(user); } @Override public void prepareForStop(String user) throws PipelineStoreException, PipelineRunnerException { runner.prepareForStop(user); } @Override public void start(String user) throws PipelineException, StageException { aclStore.validateExecutePermission(this.getName(), currentUser); runner.start(user); } @Override public void start(String user, Map<String, Object> runtimeParameters) throws PipelineException, StageException { aclStore.validateExecutePermission(this.getName(), currentUser); runner.start(user, runtimeParameters); } @Override public void startAndCaptureSnapshot( String user, Map<String, Object> runtimeParameters, String snapshotName, String snapshotLabel, int batches, int batchSize ) throws PipelineException, StageException { aclStore.validateExecutePermission(this.getName(), currentUser); runner.startAndCaptureSnapshot(user, runtimeParameters, snapshotName, snapshotLabel, batches, batchSize); } @Override public String captureSnapshot( String user, String snapshotName, String snapshotLabel, int batches, int batchSize ) throws PipelineException { aclStore.validateExecutePermission(this.getName(), currentUser); return runner.captureSnapshot(user, snapshotName, snapshotLabel, batches, batchSize); } @Override public String updateSnapshotLabel(String snapshotName, String snapshotLabel) throws PipelineException { aclStore.validateExecutePermission(this.getName(), currentUser); return runner.updateSnapshotLabel(snapshotName, snapshotLabel); } @Override public Snapshot getSnapshot(String id) throws PipelineException { return runner.getSnapshot(id); } @Override public List<SnapshotInfo> getSnapshotsInfo() throws PipelineException { return runner.getSnapshotsInfo(); } @Override public void deleteSnapshot(String id) throws PipelineException { aclStore.validateExecutePermission(this.getName(), currentUser); runner.deleteSnapshot(id); } @Override public List<PipelineState> getHistory() throws PipelineStoreException { return runner.getHistory(); } @Override public void deleteHistory() throws PipelineException { aclStore.validateWritePermission(this.getName(), currentUser); runner.deleteHistory(); } @Override public Object getMetrics() throws PipelineStoreException { return runner.getMetrics(); } @Override public List<Record> getErrorRecords(String stage, int max) throws PipelineRunnerException, PipelineStoreException { return runner.getErrorRecords(stage, max); } @Override public List<ErrorMessage> getErrorMessages( String stage, int max ) throws PipelineRunnerException, PipelineStoreException { return runner.getErrorMessages(stage, max); } @Override public List<SampledRecord> getSampledRecords( String sampleId, int max ) throws PipelineRunnerException, PipelineStoreException { return runner.getSampledRecords(sampleId, max); } @Override public List<AlertInfo> getAlerts() throws PipelineException { return runner.getAlerts(); } @Override public boolean deleteAlert(String alertId) throws PipelineException { aclStore.validateWritePermission(this.getName(), currentUser); return runner.deleteAlert(alertId); } @Override public Collection<CallbackInfo> getSlaveCallbackList(CallbackObjectType callbackObjectType) { return runner.getSlaveCallbackList(callbackObjectType); } @Override public void close() { runner.close(); } @Override public void updateSlaveCallbackInfo(CallbackInfo callbackInfo) { runner.updateSlaveCallbackInfo(callbackInfo); } @Override public Map getUpdateInfo() { return runner.getUpdateInfo(); } @Override public String getToken() { return runner.getToken(); } @Override public int getRunnerCount() { return runner.getRunnerCount(); } }