Search in sources :

Example 1 with SmartAction

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;
}
Also used : CacheFileAction(org.smartdata.hdfs.action.CacheFileAction) HdfsAction(org.smartdata.hdfs.action.HdfsAction) HashMap(java.util.HashMap) SmartAction(org.smartdata.action.SmartAction)

Example 2 with SmartAction

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();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatusMessage(org.smartdata.protocol.message.StatusMessage) ActionStatus(org.smartdata.protocol.message.ActionStatus) StatusReport(org.smartdata.protocol.message.StatusReport) SmartAction(org.smartdata.action.SmartAction) SmartConf(org.smartdata.conf.SmartConf) StatusReporter(org.smartdata.protocol.message.StatusReporter) EchoAction(org.smartdata.action.EchoAction) Test(org.junit.Test)

Example 3 with SmartAction

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;
}
Also used : LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) LaunchAction(org.smartdata.model.LaunchAction) ArrayList(java.util.ArrayList) SmartAction(org.smartdata.action.SmartAction)

Example 4 with SmartAction

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;
}
Also used : HdfsAction(org.smartdata.hdfs.action.HdfsAction) SmartAction(org.smartdata.action.SmartAction) ActionException(org.smartdata.action.ActionException) IOException(java.io.IOException) SmartDFSClient(org.smartdata.hdfs.client.SmartDFSClient)

Example 5 with 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);
        }
    }
}
Also used : AbstractMoveFileAction(org.smartdata.hdfs.action.move.AbstractMoveFileAction) MetaStoreException(org.smartdata.metastore.MetaStoreException) SmartAction(org.smartdata.action.SmartAction)

Aggregations

SmartAction (org.smartdata.action.SmartAction)8 ArrayList (java.util.ArrayList)3 ActionStatus (org.smartdata.protocol.message.ActionStatus)3 HashMap (java.util.HashMap)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Test (org.junit.Test)2 SmartConf (org.smartdata.conf.SmartConf)2 HdfsAction (org.smartdata.hdfs.action.HdfsAction)2 StatusMessage (org.smartdata.protocol.message.StatusMessage)2 StatusReport (org.smartdata.protocol.message.StatusReport)2 StatusReporter (org.smartdata.protocol.message.StatusReporter)2 IOException (java.io.IOException)1 Vector (java.util.Vector)1 ActionException (org.smartdata.action.ActionException)1 EchoAction (org.smartdata.action.EchoAction)1 CacheFileAction (org.smartdata.hdfs.action.CacheFileAction)1 AbstractMoveFileAction (org.smartdata.hdfs.action.move.AbstractMoveFileAction)1 SmartDFSClient (org.smartdata.hdfs.client.SmartDFSClient)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1 LaunchAction (org.smartdata.model.LaunchAction)1