Search in sources :

Example 1 with S3FileState

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

the class TestCopy2S3Scheduler method testOnS3.

@Test(timeout = 45000)
public void testOnS3() 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));
    List<String> sps = new ArrayList<>();
    // Write to src
    for (int i = 0; i < 3; i++) {
        // Create test files
        // Not 0 because this file may be not be truncated yet
        sps.add(srcPath + i);
        DFSTestUtil.createFile(dfs, new Path(srcPath + i), 10, (short) 1, 1);
    }
    do {
        Thread.sleep(1000);
        if (metaStore.getFilesByPaths(sps).size() == sps.size()) {
            break;
        }
    } while (true);
    for (String p : sps) {
        metaStore.insertUpdateFileState(new S3FileState(p));
    }
    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(0, actions.size());
}
Also used : Path(org.apache.hadoop.fs.Path) MetaStore(org.smartdata.metastore.MetaStore) SmartAdmin(org.smartdata.admin.SmartAdmin) ArrayList(java.util.ArrayList) ActionInfo(org.smartdata.model.ActionInfo) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) S3FileState(org.smartdata.model.S3FileState) Test(org.junit.Test)

Example 2 with S3FileState

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

the class Copy2S3Scheduler method onActionFinished.

@Override
public void onActionFinished(CmdletInfo cmdletInfo, ActionInfo actionInfo, int actionIndex) {
    String path = actionInfo.getArgs().get(HdfsAction.FILE_PATH);
    if (actionInfo.isFinished() && actionInfo.isSuccessful()) {
        // Insert fileState
        try {
            metaStore.insertUpdateFileState(new S3FileState(path));
        } catch (MetaStoreException e) {
            LOG.error("Failed to insert file state.", e);
        }
    }
    // unlock filelock
    if (ifLocked(path)) {
        unLockTheFile(path);
        LOG.debug("unlocked copy2s3 file {}", path);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) S3FileState(org.smartdata.model.S3FileState)

Example 3 with S3FileState

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

the class MetaStore method getFileState.

/**
 * Get FileState of the given path.
 *
 * @param path
 * @return
 * @throws MetaStoreException
 */
public FileState getFileState(String path) throws MetaStoreException {
    FileState fileState;
    try {
        fileState = fileStateDao.getByPath(path);
        // Fetch info from corresponding table to regenerate a specific file state
        switch(fileState.getFileType()) {
            case NORMAL:
                fileState = new NormalFileState(path);
                break;
            case COMPACT:
                fileState = smallFileDao.getFileStateByPath(path);
                break;
            case COMPRESSION:
                CompressionFileState compressionFileState = getCompressionInfo(path);
                if (compressionFileState != null) {
                    compressionFileState.setFileStage(fileState.getFileStage());
                    fileState = compressionFileState;
                }
                break;
            case S3:
                fileState = new S3FileState(path);
                break;
            default:
        }
    } catch (EmptyResultDataAccessException e1) {
        fileState = new NormalFileState(path);
    } catch (Exception e2) {
        throw new MetaStoreException(e2);
    }
    return fileState;
}
Also used : S3FileState(org.smartdata.model.S3FileState) NormalFileState(org.smartdata.model.NormalFileState) CompactFileState(org.smartdata.model.CompactFileState) FileState(org.smartdata.model.FileState) CompressionFileState(org.smartdata.model.CompressionFileState) NormalFileState(org.smartdata.model.NormalFileState) CompressionFileState(org.smartdata.model.CompressionFileState) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) S3FileState(org.smartdata.model.S3FileState) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SQLException(java.sql.SQLException)

Aggregations

S3FileState (org.smartdata.model.S3FileState)3 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Path (org.apache.hadoop.fs.Path)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 Test (org.junit.Test)1 SmartAdmin (org.smartdata.admin.SmartAdmin)1 MetaStore (org.smartdata.metastore.MetaStore)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1 ActionInfo (org.smartdata.model.ActionInfo)1 CompactFileState (org.smartdata.model.CompactFileState)1 CompressionFileState (org.smartdata.model.CompressionFileState)1 FileState (org.smartdata.model.FileState)1 NormalFileState (org.smartdata.model.NormalFileState)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1