Search in sources :

Example 16 with CmdletInfo

use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.

the class TestCmdletDao method testgetByRid.

@Test
public void testgetByRid() throws Exception {
    CmdletInfo cmdlet1 = new CmdletInfo(0, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L);
    CmdletInfo cmdlet2 = new CmdletInfo(1, 1, CmdletState.PAUSED, "tt", 123178333L, 232444994L);
    CmdletInfo cmdlet3 = new CmdletInfo(2, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L);
    CmdletInfo cmdlet4 = new CmdletInfo(3, 1, CmdletState.PAUSED, "tt", 123178333L, 232444994L);
    CmdletInfo cmdlet5 = new CmdletInfo(4, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L);
    CmdletInfo cmdlet6 = new CmdletInfo(5, 1, CmdletState.PAUSED, "tt", 123178333L, 232444994L);
    cmdletDao.insert(new CmdletInfo[] { cmdlet1, cmdlet2, cmdlet3, cmdlet4, cmdlet5, cmdlet6 });
    List<CmdletInfo> cmdlets = cmdletDao.getByRid(1, 1, 2);
    List<String> order = new ArrayList<>();
    order.add("cid");
    List<Boolean> desc = new ArrayList<>();
    desc.add(false);
    Assert.assertTrue(cmdlets.size() == 2);
    cmdlets = cmdletDao.getByRid(1, 1, 2, order, desc);
    Assert.assertTrue(cmdlets.size() == 2);
    Assert.assertTrue(cmdlets.get(0).equals(cmdlet2));
    Assert.assertTrue(cmdletDao.getNumByRid(1) == 6);
}
Also used : ArrayList(java.util.ArrayList) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 17 with CmdletInfo

use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.

the class TestMetaStore method testMoveSyncRules.

@Test
public void testMoveSyncRules() throws Exception {
    String pathString = "/src/1";
    long length = 123L;
    boolean isDir = false;
    int blockReplication = 1;
    long blockSize = 128 * 1024L;
    long modTime = 123123123L;
    long accessTime = 123123120L;
    String owner = "root";
    String group = "admin";
    long fileId = 56L;
    byte storagePolicy = 0;
    byte erasureCodingPolicy = 0;
    FileInfo fileInfo = new FileInfo(pathString, fileId, length, isDir, (short) blockReplication, blockSize, modTime, accessTime, (short) 1, owner, group, storagePolicy, erasureCodingPolicy);
    metaStore.insertFile(fileInfo);
    Map<String, String> args = new HashMap();
    args.put("-file", "/src/1");
    String rule = "file : accessCount(10m) > 20 \n\n" + "and length() > 3 | ";
    long submitTime = System.currentTimeMillis();
    RuleInfo ruleInfo = new RuleInfo(0, submitTime, rule + "sync -dest /dest/", RuleState.ACTIVE, 0, 0, 0);
    metaStore.insertNewRule(ruleInfo);
    metaStore.insertBackUpInfo(new BackUpInfo(ruleInfo.getId(), "/src/", "/dest/", 100));
    metaStore.insertNewRule(new RuleInfo(1, submitTime, rule + "allssd", RuleState.ACTIVE, 0, 0, 0));
    metaStore.insertNewRule(new RuleInfo(2, submitTime, rule + "archive", RuleState.ACTIVE, 0, 0, 0));
    metaStore.insertNewRule(new RuleInfo(2, submitTime, rule + "onessd", RuleState.ACTIVE, 0, 0, 0));
    metaStore.insertNewRule(new RuleInfo(2, submitTime, rule + "cache", RuleState.ACTIVE, 0, 0, 0));
    Assert.assertTrue(metaStore.listMoveRules().size() == 3);
    Assert.assertTrue(metaStore.listSyncRules().size() == 1);
    CmdletInfo cmdletInfo = new CmdletInfo(1, ruleInfo.getId(), CmdletState.EXECUTING, "test", 123123333L, 232444444L);
    cmdletInfo.setAids(Collections.singletonList(1L));
    metaStore.insertCmdlet(cmdletInfo);
    metaStore.insertAction(new ActionInfo(1, 1, "allssd", args, "Test", "Test", true, 123213213L, true, 123123L, 100));
    Assert.assertTrue(metaStore.listFileActions(ruleInfo.getId(), 0).size() >= 0);
}
Also used : FileInfo(org.smartdata.model.FileInfo) HashMap(java.util.HashMap) BackUpInfo(org.smartdata.model.BackUpInfo) ActionInfo(org.smartdata.model.ActionInfo) RuleInfo(org.smartdata.model.RuleInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 18 with CmdletInfo

use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.

the class TestMetaStore method testdeleteKeepNewCmdlets.

@Test
public void testdeleteKeepNewCmdlets() throws Exception {
    Map<String, String> args = new HashMap();
    CmdletInfo command1 = new CmdletInfo(0, 78, CmdletState.CANCELLED, "test", 123L, 232444444L);
    metaStore.insertCmdlet(command1);
    CmdletInfo command2 = new CmdletInfo(1, 78, CmdletState.DONE, "tt", 128L, 232444994L);
    metaStore.insertCmdlet(command2);
    ActionInfo actionInfo = new ActionInfo(1, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100);
    metaStore.insertAction(actionInfo);
    ActionInfo actionInfo2 = new ActionInfo(2, 1, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100);
    metaStore.insertAction(actionInfo2);
    ActionInfo actionInfo3 = new ActionInfo(3, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100);
    metaStore.insertAction(actionInfo3);
    metaStore.deleteKeepNewCmdlets(1);
    Assert.assertTrue(metaStore.getCmdletById(0) == null);
    Assert.assertTrue(metaStore.getActionById(1) == null);
    Assert.assertTrue(metaStore.getActionById(2) != null);
}
Also used : HashMap(java.util.HashMap) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 19 with CmdletInfo

use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.

the class CmdletManager method inferCmdletStatus.

private void inferCmdletStatus(ActionInfo actionInfo) throws IOException, ActionException {
    if (actionInfo == null) {
        return;
    }
    if (!actionInfo.isFinished()) {
        return;
    }
    long actionId = actionInfo.getActionId();
    long cmdletId = actionInfo.getCmdletId();
    CmdletInfo cmdletInfo = idToCmdlets.get(cmdletId);
    List<Long> aids = cmdletInfo.getAids();
    int index = aids.indexOf(actionId);
    if (!actionInfo.isSuccessful()) {
        for (int i = index + 1; i < aids.size(); i++) {
            // Use current action's finish time to set start/finish time for
            // subsequent action(s).
            ActionStatus actionStatus = ActionStatusFactory.createSkipActionStatus(cmdletId, i == aids.size() - 1, aids.get(i), actionInfo.getFinishTime(), actionInfo.getFinishTime());
            onActionStatusUpdate(actionStatus);
        }
        CmdletStatus cmdletStatus = new CmdletStatus(cmdletId, actionInfo.getFinishTime(), CmdletState.FAILED);
        onCmdletStatusUpdate(cmdletStatus);
    } else {
        if (index == aids.size() - 1) {
            CmdletStatus cmdletStatus = new CmdletStatus(cmdletId, actionInfo.getFinishTime(), CmdletState.DONE);
            onCmdletStatusUpdate(cmdletStatus);
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CmdletStatus(org.smartdata.protocol.message.CmdletStatus) CmdletInfo(org.smartdata.model.CmdletInfo) ActionStatus(org.smartdata.protocol.message.ActionStatus)

Example 20 with CmdletInfo

use of org.smartdata.model.CmdletInfo in project SSM by Intel-bigdata.

the class CmdletManager method scheduleCmdlet.

private int scheduleCmdlet() throws IOException {
    int nScheduled = 0;
    synchronized (pendingCmdlet) {
        if (pendingCmdlet.size() > 0) {
            schedulingCmdlet.addAll(pendingCmdlet);
            pendingCmdlet.clear();
        }
    }
    long curr = System.currentTimeMillis();
    Iterator<Long> it = schedulingCmdlet.iterator();
    while (it.hasNext() && !shouldStopSchedule()) {
        long id = it.next();
        if (nScheduled % 20 == 0) {
            curr = System.currentTimeMillis();
        }
        CmdletInfo cmdlet = idToCmdlets.get(id);
        if (cmdlet == null) {
            it.remove();
            continue;
        }
        synchronized (cmdlet) {
            switch(cmdlet.getState()) {
                case CANCELLED:
                case DISABLED:
                    it.remove();
                    break;
                case PENDING:
                    if (cmdlet.getDeferedToTime() > curr) {
                        break;
                    }
                    LaunchCmdlet launchCmdlet = createLaunchCmdlet(cmdlet);
                    ScheduleResult result;
                    try {
                        result = scheduleCmdletActions(cmdlet, launchCmdlet);
                    } catch (Throwable t) {
                        LOG.error("Schedule " + cmdlet + " failed.", t);
                        result = ScheduleResult.FAIL;
                    }
                    if (result != ScheduleResult.RETRY) {
                        it.remove();
                    } else {
                        continue;
                    }
                    try {
                        if (result == ScheduleResult.SUCCESS) {
                            idToLaunchCmdlet.put(cmdlet.getCid(), launchCmdlet);
                            cmdlet.setState(CmdletState.SCHEDULED);
                            cmdlet.setStateChangedTime(System.currentTimeMillis());
                            scheduledCmdlet.add(id);
                            nScheduled++;
                        } else if (result == ScheduleResult.FAIL) {
                            cmdlet.updateState(CmdletState.CANCELLED);
                            CmdletStatus cmdletStatus = new CmdletStatus(cmdlet.getCid(), cmdlet.getStateChangedTime(), cmdlet.getState());
                            // Mark all actions as finished
                            cmdletFinishedInternal(cmdlet, false);
                            onCmdletStatusUpdate(cmdletStatus);
                        } else if (result == ScheduleResult.SUCCESS_NO_EXECUTION) {
                            cmdlet.updateState(CmdletState.DONE);
                            cmdletFinishedInternal(cmdlet, true);
                            CmdletStatus cmdletStatus = new CmdletStatus(cmdlet.getCid(), cmdlet.getStateChangedTime(), cmdlet.getState());
                            onCmdletStatusUpdate(cmdletStatus);
                        }
                    } catch (Throwable t) {
                        LOG.error("Post schedule cmdlet " + cmdlet + " error.", t);
                    }
                    break;
            }
        }
    }
    return nScheduled;
}
Also used : ScheduleResult(org.smartdata.model.action.ScheduleResult) AtomicLong(java.util.concurrent.atomic.AtomicLong) LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) CmdletStatus(org.smartdata.protocol.message.CmdletStatus) CmdletInfo(org.smartdata.model.CmdletInfo)

Aggregations

CmdletInfo (org.smartdata.model.CmdletInfo)37 Test (org.junit.Test)18 ActionInfo (org.smartdata.model.ActionInfo)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 HashMap (java.util.HashMap)4 MetaStore (org.smartdata.metastore.MetaStore)3 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)3 CmdletState (org.smartdata.model.CmdletState)3 RuleInfo (org.smartdata.model.RuleInfo)3 CmdletStatus (org.smartdata.protocol.message.CmdletStatus)3 ServiceException (com.google.protobuf.ServiceException)2 ParseException (java.text.ParseException)2 SmartAdmin (org.smartdata.admin.SmartAdmin)2 QueueFullException (org.smartdata.exception.QueueFullException)2 MetaStoreException (org.smartdata.metastore.MetaStoreException)2 FileInfo (org.smartdata.model.FileInfo)2 CmdletInfoProto (org.smartdata.protocol.AdminServerProto.CmdletInfoProto)2 ActionStatus (org.smartdata.protocol.message.ActionStatus)2