Search in sources :

Example 16 with SmartAdmin

use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.

the class TestRuleExecutorPlugin method testPlugin.

@Test
public void testPlugin() throws Exception {
    waitTillSSMExitSafeMode();
    TestPlugin plugin = new TestPlugin();
    try {
        RuleExecutorPluginManager.addPlugin(plugin);
        RuleExecutorPluginManager.addPlugin(plugin);
        String rule = "file: every 1s \n | length > 10 | cache";
        SmartAdmin client = new SmartAdmin(smartContext.getConf());
        long ruleId = client.submitRule(rule, RuleState.ACTIVE);
        Assert.assertEquals(plugin.getNumOnNewRuleExecutor(), 1);
        Thread.sleep(3000);
        Assert.assertEquals(plugin.getNumOnNewRuleExecutor(), 1);
        Assert.assertTrue(plugin.getNumPreExecution() >= 2);
        Assert.assertTrue(plugin.getNumPreSubmitCmdlet() >= 2);
        Assert.assertTrue(plugin.getNumOnRuleExecutorExit() == 0);
        client.disableRule(ruleId, true);
        Thread.sleep(1100);
        int numPreExecution = plugin.getNumPreExecution();
        int numPreSubmitCmdlet = plugin.getNumPreSubmitCmdlet();
        Thread.sleep(2500);
        Assert.assertTrue(plugin.getNumOnNewRuleExecutor() == 1);
        Assert.assertTrue(plugin.getNumPreExecution() == numPreExecution);
        Assert.assertTrue(plugin.getNumPreSubmitCmdlet() == numPreSubmitCmdlet);
        Assert.assertTrue(plugin.getNumOnRuleExecutorExit() == 1);
        RuleExecutorPluginManager.deletePlugin(plugin);
        client.activateRule(ruleId);
        Thread.sleep(500);
        Assert.assertTrue(plugin.getNumOnNewRuleExecutor() == 1);
        Assert.assertTrue(plugin.getNumPreExecution() == numPreExecution);
    } finally {
        RuleExecutorPluginManager.deletePlugin(plugin);
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) Test(org.junit.Test)

Example 17 with SmartAdmin

use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.

the class TestRulePlugin method testPlugin.

@Test
public void testPlugin() throws Exception {
    waitTillSSMExitSafeMode();
    SimplePlugin plugin = new SimplePlugin();
    try {
        RulePluginManager.addPlugin(plugin);
        int adding = plugin.getAdding();
        int added = plugin.getAdded();
        SmartAdmin admin = new SmartAdmin(smartContext.getConf());
        admin.submitRule("file : path matches \"/home/*\" | cache", RuleState.ACTIVE);
        Assert.assertTrue(adding + 1 == plugin.getAdding());
        Assert.assertTrue(added + 1 == plugin.getAdded());
        try {
            admin.submitRule("file : path matches \"/user/*\" | cache", RuleState.DISABLED);
            Assert.fail("Should not success.");
        } catch (Exception e) {
            Assert.assertTrue(e.getMessage().contains("MUST ACTIVE"));
        }
        Assert.assertTrue(adding + 1 == plugin.getAdding());
        Assert.assertTrue(added + 1 == plugin.getAdded());
    } finally {
        RulePluginManager.deletePlugin(plugin);
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) IOException(java.io.IOException) Test(org.junit.Test)

Example 18 with SmartAdmin

use of org.smartdata.admin.SmartAdmin in project SSM by Intel-bigdata.

the class TestCopy2S3Scheduler method testZeroLength.

@Test(timeout = 45000)
public void testZeroLength() throws Exception {
    waitTillSSMExitSafeMode();
    MetaStore metaStore = ssm.getMetaStore();
    SmartAdmin admin = new SmartAdmin(smartContext.getConf());
    DistributedFileSystem dfs = cluster.getFileSystem();
    final String srcPath = "/src/";
    dfs.mkdirs(new Path(srcPath));
    // Write to src
    for (int i = 0; i < 3; i++) {
        // Create test files
        DFSTestUtil.createFile(dfs, new Path(srcPath + i), 0, (short) 1, 1);
    }
    long ruleId = admin.submitRule("file: path matches \"/src/*\"| copy2s3 -dest s3a://xxxctest/dest/", RuleState.ACTIVE);
    Thread.sleep(2500);
    List<ActionInfo> actions = metaStore.getActions(ruleId, 0);
    Assert.assertEquals(actions.size(), 0);
}
Also used : Path(org.apache.hadoop.fs.Path) MetaStore(org.smartdata.metastore.MetaStore) SmartAdmin(org.smartdata.admin.SmartAdmin) ActionInfo(org.smartdata.model.ActionInfo) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) Test(org.junit.Test)

Example 19 with SmartAdmin

use of org.smartdata.admin.SmartAdmin 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)

Aggregations

SmartAdmin (org.smartdata.admin.SmartAdmin)19 Test (org.junit.Test)15 IOException (java.io.IOException)7 ActionInfo (org.smartdata.model.ActionInfo)5 RuleInfo (org.smartdata.model.RuleInfo)4 Path (org.apache.hadoop.fs.Path)3 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)3 RuleInfo (org.smartdata.common.rule.RuleInfo)3 MetaStore (org.smartdata.metastore.MetaStore)3 SmartServiceState (org.smartdata.SmartServiceState)2 CmdletInfo (org.smartdata.model.CmdletInfo)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 SmartServiceState (org.smartdata.common.SmartServiceState)1 SmartConf (org.smartdata.conf.SmartConf)1 ActionDescriptor (org.smartdata.model.ActionDescriptor)1 S3FileState (org.smartdata.model.S3FileState)1