use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.
the class TestCmdlet method runHelper.
private Cmdlet runHelper() throws IOException {
SmartAction[] actions = new SmartAction[4];
// New action
// actions[0] = new AllSsdFileAction();
// actions[0].setDfsClient(client);
// actions[0].setContext(new SmartContext(smartConf));
// actions[0].getDNStorageReports(new String[]{"/testMoveFile/file1"});
// actions[1] = new MoveFileAction();
// actions[1].setDfsClient(client);
// actions[1].setContext(new SmartContext(smartConf));
// actions[1].getDNStorageReports(new String[]{"/testMoveFile/file2", "COLD"});
actions[2] = new CacheFileAction();
((HdfsAction) actions[2]).setDfsClient(dfsClient);
actions[2].setContext(smartContext);
Map<String, String> args = new HashMap();
args.put(CacheFileAction.FILE_PATH, "/testCacheFile");
actions[2].init(args);
// New Cmdlet
Cmdlet cmd = new Cmdlet(Arrays.asList(actions));
cmd.setId(1);
cmd.setRuleId(1);
cmd.setState(CmdletState.PENDING);
return cmd;
}
use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.
the class TestCmdletExecutor method testCmdletExecutor.
@Test
public void testCmdletExecutor() throws InterruptedException {
final List<StatusMessage> statusMessages = new ArrayList<>();
StatusReporter reporter = new StatusReporter() {
@Override
public void report(StatusMessage status) {
statusMessages.add(status);
}
};
CmdletExecutor executor = new CmdletExecutor(new SmartConf());
StatusReportTask statusReportTask = new StatusReportTask(reporter, executor, new SmartConf());
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(statusReportTask, 100, 10, TimeUnit.MILLISECONDS);
SmartAction action = new EchoAction();
Map<String, String> args = new HashMap<>();
args.put(EchoAction.PRINT_MESSAGE, "message success");
action.setArguments(args);
action.setActionId(101);
Cmdlet cmdlet = new Cmdlet(Arrays.asList(action));
executor.execute(cmdlet);
Thread.sleep(2000);
StatusReport lastReport = (StatusReport) statusMessages.get(statusMessages.size() - 1);
ActionStatus status = lastReport.getActionStatuses().get(0);
Assert.assertTrue(status.isFinished());
Assert.assertNull(status.getThrowable());
executor.shutdown();
}
use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.
the class CmdletFactory method createCmdlet.
public Cmdlet createCmdlet(LaunchCmdlet launchCmdlet) throws ActionException {
List<SmartAction> actions = new ArrayList<>();
int idx = 0;
for (LaunchAction action : launchCmdlet.getLaunchActions()) {
idx++;
actions.add(createAction(launchCmdlet.getCmdletId(), idx == launchCmdlet.getLaunchActions().size(), action));
}
Cmdlet cmdlet = new Cmdlet(actions);
cmdlet.setId(launchCmdlet.getCmdletId());
return cmdlet;
}
use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.
the class CmdletFactory method createAction.
public SmartAction createAction(long cmdletId, boolean isLastAction, LaunchAction launchAction) throws ActionException {
SmartAction smartAction = ActionRegistry.createAction(launchAction.getActionType());
smartAction.setContext(smartContext);
smartAction.setCmdletId(cmdletId);
smartAction.setLastAction(isLastAction);
smartAction.init(launchAction.getArgs());
smartAction.setActionId(launchAction.getActionId());
if (smartAction instanceof HdfsAction) {
try {
((HdfsAction) smartAction).setDfsClient(new SmartDFSClient(HadoopUtil.getNameNodeUri(smartContext.getConf()), smartContext.getConf(), getRpcServerAddress()));
} catch (IOException e) {
LOG.error("smartAction aid={} setDfsClient error", launchAction.getActionId(), e);
throw new ActionException(e);
}
}
/*
else if (smartAction instanceof AlluxioAction) {
FileSystem fs;
try {
fs = AlluxioUtil.getAlluxioFs(smartContext);
} catch (Exception e) {
LOG.error("smartAction aid={} alluxio filesystem error", launchAction.getActionId(), e);
throw new ActionException(e);
}
((AlluxioAction) smartAction).setFileSystem(fs);
}
*/
return smartAction;
}
use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.
the class CmdletManager method updateStorageIfNeeded.
// Todo: remove this implementation
private void updateStorageIfNeeded(ActionInfo info) throws ActionException {
SmartAction action = ActionRegistry.createAction(info.getActionName());
if (action instanceof AbstractMoveFileAction) {
String policy = ((AbstractMoveFileAction) action).getStoragePolicy();
Map<String, String> args = info.getArgs();
if (policy == null) {
policy = args.get(AbstractMoveFileAction.STORAGE_POLICY);
}
String path = args.get(AbstractMoveFileAction.FILE_PATH);
try {
String result = info.getResult();
result = result == null ? "" : result;
if (!result.contains("UpdateStoragePolicy=false")) {
metaStore.updateFileStoragePolicy(path, policy);
}
} catch (MetaStoreException e) {
LOG.error("Failed to update storage policy {} for file {}", policy, path, e);
}
}
}
Aggregations