Search in sources :

Example 1 with ErasureCodingPolicyInfo

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

the class NamespaceFetcher method startFetch.

public void startFetch() throws IOException {
    try {
        init(conf);
        metaStore.deleteAllEcPolicies();
        Map<Byte, String> idToPolicyName = CompatibilityHelperLoader.getHelper().getErasureCodingPolicies(client);
        if (idToPolicyName != null) {
            ArrayList<ErasureCodingPolicyInfo> ecInfos = new ArrayList<>();
            for (Byte id : idToPolicyName.keySet()) {
                ecInfos.add(new ErasureCodingPolicyInfo(id, idToPolicyName.get(id)));
            }
            metaStore.insertEcPolicies(ecInfos);
            LOG.info("Finished fetching all EC policies!");
        }
    } catch (MetaStoreException e) {
        throw new IOException("Failed to clean and fetch EC policies!");
    }
    try {
        metaStore.deleteAllFileInfo();
    } catch (MetaStoreException e) {
        throw new IOException("Error while reset files", e);
    }
    this.fetchTaskFutures = new ScheduledFuture[ingestionTasks.length];
    for (int i = 0; i < ingestionTasks.length; i++) {
        fetchTaskFutures[i] = this.scheduledExecutorService.scheduleAtFixedRate(ingestionTasks[i], 0, fetchInterval, TimeUnit.MILLISECONDS);
    }
    this.consumerFutures = new ScheduledFuture[consumers.length];
    for (int i = 0; i < consumers.length; i++) {
        consumerFutures[i] = this.scheduledExecutorService.scheduleAtFixedRate(consumers[i], 0, fetchInterval, TimeUnit.MILLISECONDS);
    }
    LOG.info("Started.");
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ErasureCodingPolicyInfo(org.smartdata.model.ErasureCodingPolicyInfo)

Example 2 with ErasureCodingPolicyInfo

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

the class ErasureCodingPlugin method preExecution.

@Override
public boolean preExecution(RuleInfo ruleInfo, TranslateResult tResult) {
    if (!ecPolicies.containsKey(ruleInfo.getId())) {
        return true;
    }
    List<String> polices = ecPolicies.get(ruleInfo.getId());
    String notIn = null;
    synchronized (ecInfos) {
        for (String policy : polices) {
            notIn = policy;
            for (ErasureCodingPolicyInfo info : ecInfos) {
                if (info.getEcPolicyName().equals(policy)) {
                    notIn = null;
                    break;
                }
            }
            if (notIn != null) {
                break;
            }
        }
    }
    if (notIn != null) {
        synchronized (ecInfos) {
            long curr = System.currentTimeMillis();
            if (curr - lastUpdateTime >= 5000) {
                LOG.info("Refresh EC policies for policy: " + notIn);
                updateErasureCodingPolices();
                lastUpdateTime = curr;
            }
        }
    }
    return true;
}
Also used : ErasureCodingPolicyInfo(org.smartdata.model.ErasureCodingPolicyInfo)

Example 3 with ErasureCodingPolicyInfo

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

the class ErasureCodingPlugin method updateErasureCodingPolices.

private void updateErasureCodingPolices() {
    try {
        initClient();
        if (client == null) {
            LOG.error("Failed to refresh EC policies due to can not setup connection to HDFS!");
            return;
        }
        Map<Byte, String> idToPolicyName = CompatibilityHelperLoader.getHelper().getErasureCodingPolicies(client);
        if (idToPolicyName != null) {
            ecInfos.clear();
            for (Byte id : idToPolicyName.keySet()) {
                ecInfos.add(new ErasureCodingPolicyInfo(id, idToPolicyName.get(id)));
            }
            metaStore.deleteAllEcPolicies();
            metaStore.insertEcPolicies(ecInfos);
        }
    } catch (Exception e) {
        LOG.warn("Failed to refresh EC policies!");
    }
}
Also used : ErasureCodingPolicyInfo(org.smartdata.model.ErasureCodingPolicyInfo)

Example 4 with ErasureCodingPolicyInfo

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

the class TestErasureCodingPolicyDao method testInsertAll.

@Test
public void testInsertAll() throws Exception {
    ecPolicyDao.deleteAll();
    List<ErasureCodingPolicyInfo> list = new ArrayList<>();
    list.add(new ErasureCodingPolicyInfo((byte) 1, "PolicyInfo1"));
    list.add(new ErasureCodingPolicyInfo((byte) 3, "PolicyInfo3"));
    ecPolicyDao.insert(list);
    List<ErasureCodingPolicyInfo> getList = ecPolicyDao.getAllEcPolicies();
    Assert.assertTrue(getList.get(0).equals(list.get(0)) && getList.get(1).equals(list.get(1)));
}
Also used : ArrayList(java.util.ArrayList) ErasureCodingPolicyInfo(org.smartdata.model.ErasureCodingPolicyInfo) Test(org.junit.Test)

Example 5 with ErasureCodingPolicyInfo

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

the class TestErasureCodingPolicyDao method testInsert.

@Test
public void testInsert() throws Exception {
    ErasureCodingPolicyInfo ecPolicyInfo = new ErasureCodingPolicyInfo((byte) 2, "PolicyInfo1");
    ecPolicyDao.insert(ecPolicyInfo);
    Assert.assertTrue(ecPolicyDao.getEcPolicyByName("PolicyInfo1").equals(ecPolicyInfo));
    Assert.assertTrue(ecPolicyDao.getEcPolicyById((byte) 2).equals(ecPolicyInfo));
}
Also used : ErasureCodingPolicyInfo(org.smartdata.model.ErasureCodingPolicyInfo) Test(org.junit.Test)

Aggregations

ErasureCodingPolicyInfo (org.smartdata.model.ErasureCodingPolicyInfo)5 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1