Search in sources :

Example 26 with CmdletInfo

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

the class TestCmdletManager method testSubmitAPI.

@Test
public void testSubmitAPI() throws Exception {
    waitTillSSMExitSafeMode();
    DistributedFileSystem dfs = cluster.getFileSystem();
    Path dir = new Path("/testMoveFile");
    dfs.mkdirs(dir);
    // Move to SSD
    dfs.setStoragePolicy(dir, "HOT");
    FSDataOutputStream out1 = dfs.create(new Path("/testMoveFile/file1"), true, 1024);
    out1.writeChars("/testMoveFile/file1");
    out1.close();
    Path dir3 = new Path("/testCacheFile");
    dfs.mkdirs(dir3);
    Assert.assertTrue(ActionRegistry.supportedActions().size() > 0);
    CmdletManager cmdletManager = ssm.getCmdletManager();
    long cmdId = cmdletManager.submitCmdlet("allssd -file /testMoveFile/file1 ; cache -file /testCacheFile ; " + "write -file /test -length 1024");
    Thread.sleep(1200);
    List<ActionInfo> actionInfos = cmdletManager.listNewCreatedActions(10);
    Assert.assertTrue(actionInfos.size() > 0);
    while (true) {
        CmdletState state = cmdletManager.getCmdletInfo(cmdId).getState();
        if (state == CmdletState.DONE) {
            break;
        }
        Assert.assertFalse(CmdletState.isTerminalState(state));
        System.out.printf("Cmdlet still running.\n");
        Thread.sleep(1000);
    }
    List<CmdletInfo> com = ssm.getMetaStore().getCmdlets(null, null, CmdletState.DONE);
    Assert.assertTrue(com.size() >= 1);
    List<ActionInfo> result = ssm.getMetaStore().getActions(null, null);
    Assert.assertTrue(result.size() == 3);
}
Also used : Path(org.apache.hadoop.fs.Path) CmdletState(org.smartdata.model.CmdletState) ActionInfo(org.smartdata.model.ActionInfo) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 27 with CmdletInfo

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

the class TestMetaStore method testdeleteFinishedCmdletsWithGenTimeBefore.

@Test
public void testdeleteFinishedCmdletsWithGenTimeBefore() 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.deleteFinishedCmdletsWithGenTimeBefore(125);
    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 28 with CmdletInfo

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

the class TestMetaStore method testUpdateDeleteCommand.

@Test
public void testUpdateDeleteCommand() throws Exception {
    long commandId = 0;
    commandId = metaStore.getMaxCmdletId();
    System.out.printf("CommandID = %d\n", commandId);
    CmdletInfo command1 = new CmdletInfo(0, 1, CmdletState.PENDING, "test", 123123333L, 232444444L);
    CmdletInfo command2 = new CmdletInfo(1, 78, CmdletState.PENDING, "tt", 123178333L, 232444994L);
    CmdletInfo[] commands = { command1, command2 };
    metaStore.insertCmdlets(commands);
    String cidCondition = ">= 1 ";
    String ridCondition = "= 78 ";
    List<CmdletInfo> com = metaStore.getCmdlets(cidCondition, ridCondition, CmdletState.PENDING);
    commandId = metaStore.getMaxCmdletId();
    Assert.assertTrue(commandId == commands.length);
    for (CmdletInfo cmd : com) {
        // System.out.printf("Cid = %d \n", cmd.getCid());
        metaStore.updateCmdlet(cmd.getCid(), CmdletState.DONE);
    }
    List<CmdletInfo> com1 = metaStore.getCmdlets(cidCondition, ridCondition, CmdletState.DONE);
    Assert.assertTrue(com1.size() == 1);
    Assert.assertTrue(com1.get(0).getState().equals(CmdletState.DONE));
    metaStore.deleteCmdlet(command2.getCid());
    com1 = metaStore.getCmdlets(cidCondition, ridCondition, CmdletState.DONE);
    Assert.assertTrue(com1.size() == 0);
}
Also used : CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 29 with CmdletInfo

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

the class TestSmartAdmin method test.

@Test
public void test() throws Exception {
    waitTillSSMExitSafeMode();
    SmartAdmin admin = null;
    try {
        admin = new SmartAdmin(smartContext.getConf());
        // test listRulesInfo and submitRule
        List<RuleInfo> ruleInfos = admin.listRulesInfo();
        int ruleCounts0 = ruleInfos.size();
        long ruleId = admin.submitRule("file: every 5s | path matches \"/foo*\"| cache", RuleState.DRYRUN);
        ruleInfos = admin.listRulesInfo();
        int ruleCounts1 = ruleInfos.size();
        assertEquals(1, ruleCounts1 - ruleCounts0);
        // test checkRule
        // if success ,no Exception throw
        admin.checkRule("file: every 5s | path matches \"/foo*\"| cache");
        boolean caughtException = false;
        try {
            admin.checkRule("file.path");
        } catch (IOException e) {
            caughtException = true;
        }
        assertTrue(caughtException);
        // test getRuleInfo
        RuleInfo ruleInfo = admin.getRuleInfo(ruleId);
        assertNotEquals(null, ruleInfo);
        // test disableRule
        admin.disableRule(ruleId, true);
        assertEquals(RuleState.DISABLED, admin.getRuleInfo(ruleId).getState());
        // test activateRule
        admin.activateRule(ruleId);
        assertEquals(RuleState.ACTIVE, admin.getRuleInfo(ruleId).getState());
        // test deleteRule
        admin.deleteRule(ruleId, true);
        assertEquals(RuleState.DELETED, admin.getRuleInfo(ruleId).getState());
        // test cmdletInfo
        long id = admin.submitCmdlet("cache -file /foo*");
        CmdletInfo cmdletInfo = admin.getCmdletInfo(id);
        assertTrue("cache -file /foo*".equals(cmdletInfo.getParameters()));
        // test actioninfo
        List<Long> aidlist = cmdletInfo.getAids();
        assertNotEquals(0, aidlist.size());
        ActionInfo actionInfo = admin.getActionInfo(aidlist.get(0));
        assertEquals(id, actionInfo.getCmdletId());
        // test listActionInfoOfLastActions
        admin.listActionInfoOfLastActions(2);
        List<ActionDescriptor> actions = admin.listActionsSupported();
        assertTrue(actions.size() > 0);
        // test client close
        admin.close();
        try {
            admin.getRuleInfo(ruleId);
            Assert.fail("Should fail because admin has closed.");
        } catch (IOException e) {
        }
        admin = null;
    } finally {
        if (admin != null) {
            admin.close();
        }
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) ActionDescriptor(org.smartdata.model.ActionDescriptor) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException) RuleInfo(org.smartdata.model.RuleInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 30 with CmdletInfo

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

the class TestCmdletDao method testGetAPageOfAction.

@Test
public void testGetAPageOfAction() {
    CmdletInfo cmdlet1 = new CmdletInfo(0, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L);
    CmdletInfo cmdlet2 = new CmdletInfo(1, 78, CmdletState.PAUSED, "tt", 123178333L, 232444994L);
    cmdletDao.insert(new CmdletInfo[] { cmdlet1, cmdlet2 });
    List<String> order = new ArrayList<>();
    order.add("cid");
    List<Boolean> desc = new ArrayList<>();
    desc.add(false);
    Assert.assertTrue(cmdletDao.getAPageOfCmdlet(1, 1, order, desc).get(0).equals(cmdlet2));
}
Also used : ArrayList(java.util.ArrayList) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

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