本文整理了Java中org.apache.kylin.common.persistence.ResourceStore.checkAndPutResource
方法的一些代码示例,展示了ResourceStore.checkAndPutResource
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResourceStore.checkAndPutResource
方法的具体详情如下:
包路径:org.apache.kylin.common.persistence.ResourceStore
类名称:ResourceStore
方法名:checkAndPutResource
[英]check & set, overwrite a resource
[中]选中并设置,覆盖资源(&S)
代码示例来源:origin: apache/kylin
private void writeJobResource(String path, ExecutablePO job) throws IOException {
store.checkAndPutResource(path, job, JOB_SERIALIZER);
}
代码示例来源:origin: apache/kylin
private void writeJobOutputResource(String path, ExecutableOutputPO output) throws IOException {
store.checkAndPutResource(path, output, JOB_OUTPUT_SERIALIZER);
}
代码示例来源:origin: apache/kylin
/**
* check & set, overwrite a resource
*/
final public <T extends RootPersistentEntity> void checkAndPutResource(String resPath, T obj, Serializer<T> serializer)
throws IOException, WriteConflictException {
checkAndPutResource(resPath, obj, System.currentTimeMillis(), serializer);
}
代码示例来源:origin: apache/kylin
private static ResourceStore createResourceStore(KylinConfig kylinConfig) {
StorageURL metadataUrl = kylinConfig.getMetadataUrl();
logger.info("Using metadata url " + metadataUrl + " for resource store");
String clsName = kylinConfig.getResourceStoreImpls().get(metadataUrl.getScheme());
try {
Class<? extends ResourceStore> cls = ClassUtil.forName(clsName, ResourceStore.class);
ResourceStore store = cls.getConstructor(KylinConfig.class).newInstance(kylinConfig);
if (!store.exists(METASTORE_UUID_TAG)) {
store.checkAndPutResource(METASTORE_UUID_TAG, new StringEntity(store.createMetaStoreUUID()), 0,
StringEntity.serializer);
}
return store;
} catch (Throwable e) {
throw new IllegalArgumentException("Failed to find metadata store by url: " + metadataUrl, e);
}
}
代码示例来源:origin: apache/kylin
private void updateCubeDesc(CubeDesc cubeDesc) {
try {
String calculatedSign = cubeDesc.calculateSignature();
if (cubeDesc.getSignature() == null || (!cubeDesc.getSignature().equals(calculatedSign))) {
cubeDesc.setSignature(calculatedSign);
store.checkAndPutResource(cubeDesc.getResourcePath(), cubeDesc, CubeDesc.newSerializerForLowLevelAccess());
updatedResources.add(cubeDesc.getResourcePath());
}
} catch (Exception e) {
logger.error("error", e);
errorMsgs.add("Update CubeDesc[" + cubeDesc.getName() + "] failed: " + e.getLocalizedMessage());
}
}
代码示例来源:origin: apache/kylin
public T save(T entity) throws IOException {
Preconditions.checkArgument(entity != null);
completeUuidIfNeeded(entity);
Preconditions.checkArgument(entityType.isInstance(entity));
String resName = entity.resourceName();
Preconditions.checkArgument(resName != null && resName.length() > 0);
if (checkCopyOnWrite) {
if (entity.isCachedAndShared() || cache.get(resName) == entity) {
throw new IllegalStateException("Copy-on-write violation! The updating entity " + entity
+ " is a shared object in " + entityType.getSimpleName() + " cache, which should not be.");
}
}
String path = resourcePath(resName);
logger.debug("Saving {} at {}", entityType.getSimpleName(), path);
store.checkAndPutResource(path, entity, serializer);
// just to trigger the event broadcast, the entity won't stay in cache
cache.put(resName, entity);
// keep the pass-in entity out of cache, the caller may use it for further update
// return a reloaded new object
return reload(resName);
}
代码示例来源:origin: apache/kylin
public void save(ExtTableSnapshotInfo snapshot) throws IOException {
ResourceStore store = TableMetadataManager.getInstance(this.config).getStore();
String path = snapshot.getResourcePath();
store.checkAndPutResource(path, snapshot, SNAPSHOT_SERIALIZER);
}
代码示例来源:origin: apache/kylin
private void convertToResourceStore(KylinConfig kylinConfig, String tableName, ResourceStore store,
ResultConverter converter) throws IOException {
Table table = null;
ResultScanner rs = null;
Scan scan = new Scan();
try {
table = HBaseConnection.get(kylinConfig.getStorageUrl()).getTable(TableName.valueOf(tableName));
rs = table.getScanner(scan);
converter.convertResult(rs, store);
store.checkAndPutResource(MIGRATE_OK_PREFIX + tableName, new StringEntity(tableName + " migrated"),
StringEntity.serializer);
} finally {
IOUtils.closeQuietly(rs);
IOUtils.closeQuietly(table);
}
}
代码示例来源:origin: apache/kylin
/**
* check & set, overwrite a resource
*/
final public <T extends RootPersistentEntity> void checkAndPutResource(String resPath, T obj, long newTS,
Serializer<T> serializer) throws IOException, WriteConflictException {
resPath = norm(resPath);
//logger.debug("Saving resource " + resPath + " (Store " + kylinConfig.getMetadataUrl() + ")");
long oldTS = obj.getLastModified();
obj.setLastModified(newTS);
try {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(buf);
serializer.serialize(obj, dout);
dout.close();
buf.close();
long confirmedTS = checkAndPutResource(resPath, buf.toByteArray(), oldTS, newTS);
obj.setLastModified(confirmedTS); // update again the confirmed TS
//return confirmedTS;
} catch (IOException e) {
obj.setLastModified(oldTS); // roll back TS when write fail
throw e;
} catch (RuntimeException e) {
obj.setLastModified(oldTS); // roll back TS when write fail
throw e;
}
}
代码示例来源:origin: apache/kylin
public void save(Draft draft) throws IOException {
if (draft.getUuid() == null) {
throw new IllegalArgumentException();
}
Draft youngerSelf = load(draft.getUuid());
if (youngerSelf != null) {
draft.setLastModified(youngerSelf.getLastModified());
}
ResourceStore store = getStore();
store.checkAndPutResource(draft.getResourcePath(), draft, DRAFT_SERIALIZER);
logger.trace("Saved " + draft);
}
代码示例来源:origin: apache/kylin
public BadQueryHistory upsertEntryToProject(BadQueryEntry badQueryEntry, String project) throws IOException {
if (StringUtils.isEmpty(project) || badQueryEntry.getAdj() == null || badQueryEntry.getSql() == null)
throw new IllegalArgumentException();
BadQueryHistory badQueryHistory = getBadQueriesForProject(project);
NavigableSet<BadQueryEntry> entries = badQueryHistory.getEntries();
entries.remove(badQueryEntry); // in case the entry already exists and this call means to update
entries.add(badQueryEntry);
int maxSize = kylinConfig.getBadQueryHistoryNum();
if (entries.size() > maxSize) {
entries.pollFirst();
}
getStore().checkAndPutResource(badQueryHistory.getResourcePath(), badQueryHistory, BAD_QUERY_INSTANCE_SERIALIZER);
return badQueryHistory;
}
代码示例来源:origin: apache/kylin
public String getMetaStoreUUID() throws IOException {
if (!exists(ResourceStore.METASTORE_UUID_TAG)) {
checkAndPutResource(ResourceStore.METASTORE_UUID_TAG, new StringEntity(createMetaStoreUUID()), 0,
StringEntity.serializer);
}
StringEntity entity = getResource(ResourceStore.METASTORE_UUID_TAG, StringEntity.serializer);
return entity.toString();
}
代码示例来源:origin: apache/kylin
trimmedCube.getSegments().clear();
trimmedCube.setUuid(cube.getUuid());
dstStore.checkAndPutResource(trimmedCube.getResourcePath(), trimmedCube, CubeManager.CUBE_SERIALIZER);
代码示例来源:origin: apache/kylin
private HybridInstance create(String hybridName, List<RealizationEntry> realizationEntries, String projectName, String owner) throws IOException {
checkSegmentOffset(realizationEntries);
HybridInstance hybridInstance = HybridInstance.create(kylinConfig, hybridName, realizationEntries);
store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
hybridManager.reloadHybridInstance(hybridName);
logger.info("HybridInstance was created at: " + hybridInstance.getResourcePath());
return hybridInstance;
}
代码示例来源:origin: apache/kylin
private void update(HybridInstance hybridInstance, List<RealizationEntry> realizationEntries, String projectName, String owner, boolean checkCubeSize) throws IOException {
if (checkCubeSize)
checkSegmentOffset(realizationEntries);
hybridInstance.setRealizationEntries(realizationEntries);
store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
hybridManager.reloadHybridInstance(hybridInstance.getName());
logger.info("HybridInstance was updated at: " + hybridInstance.getResourcePath());
}
代码示例来源:origin: apache/kylin
private static void testGetAllResources(ResourceStore store) throws IOException {
final String folder = "/testFolder";
List<StringEntity> result;
// reset any leftover garbage
new ResourceTool().resetR(store, folder);
store.checkAndPutResource(folder + "/res1", new StringEntity("data1"), 1000, StringEntity.serializer);
store.checkAndPutResource(folder + "/res2", new StringEntity("data2"), 2000, StringEntity.serializer);
store.checkAndPutResource(folder + "/sub/res3", new StringEntity("data3"), 3000, StringEntity.serializer);
store.checkAndPutResource(folder + "/res4", new StringEntity("data4"), 4000, StringEntity.serializer);
result = store.getAllResources(folder, StringEntity.serializer);
Collections.sort(result);
assertEntity(result.get(0), "data1", 1000);
assertEntity(result.get(1), "data2", 2000);
assertEntity(result.get(2), "data4", 4000);
assertEquals(3, result.size());
result = store.getAllResources(folder, false, new ResourceStore.VisitFilter(2000, 4000),
new ContentReader(StringEntity.serializer));
assertEntity(result.get(0), "data2", 2000);
assertEquals(1, result.size());
new ResourceTool().resetR(store, folder);
}
代码示例来源:origin: apache/kylin
dstStore.checkAndPutResource(cubeResPath, cube, cubeSerializer);
logger.info("Item " + item + " is dup, instead " + dictSaved.getResourcePath() + " is reused");
dstStore.checkAndPutResource(cubeResPath, cube, cubeSerializer);
logger.info("Item " + item + " is dup, instead " + snapSaved.getResourcePath() + " is reused");
project.addRealizationEntry(RealizationType.CUBE, cubeName);
dstStore.checkAndPutResource(projectResPath, project, projectSerializer);
logger.info("Project instance for " + projectName + " is corrected");
break;
cubeInstance.setCreateTimeUTC(System.currentTimeMillis());
cubeInstance.setStatus(RealizationStatusEnum.DISABLED);
dstStore.checkAndPutResource(cubeInstancePath, cubeInstance, cubeInstanceSerializer);
logger.info("Cleared segments for " + cubeName + ", since segments has not been copied");
break;
cube.getSegments().clear();
cube.setStatus(RealizationStatusEnum.DISABLED);
srcStore.checkAndPutResource(cubeResPath, cube, cubeSerializer);
logger.info("Cube " + cubeName + " is purged and disabled in " + srcConfig.getMetadataUrl());
代码示例来源:origin: apache/kylin
store.checkAndPutResource(cubeInstance.getResourcePath(), cubeInstance, CubeManager.CUBE_SERIALIZER);
logger.info("CubeInstance was saved at: " + cubeInstance.getResourcePath());
realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, newCubeInstance.getName()));
HybridInstance hybridInstance = HybridInstance.create(kylinConfig, renameHybrid(cubeInstance.getName()), realizationEntries);
store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
logger.info("HybridInstance was saved at: " + hybridInstance.getResourcePath());
代码示例来源:origin: apache/kylin
store.checkAndPutResource(cubeInstance.getResourcePath(), cubeInstance, CubeManager.CUBE_SERIALIZER);
logger.info("CubeInstance was saved at: " + cubeInstance.getResourcePath());
realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, newCubeInstance.getName()));
HybridInstance hybridInstance = HybridInstance.create(kylinConfig, renameHybrid(cubeInstance.getName()), realizationEntries);
store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
logger.info("HybridInstance was saved at: " + hybridInstance.getResourcePath());
代码示例来源:origin: apache/kylin
store.checkAndPutResource(path1, content1, StringEntity.serializer);
assertTrue(store.exists(path1));
t = store.getResource(path1, StringEntity.serializer);
assertEquals(content1, t);
store.checkAndPutResource(path2, content2, StringEntity.serializer);
assertTrue(store.exists(path2));
t = store.getResource(path2, StringEntity.serializer);
store.checkAndPutResource(path2, t, StringEntity.serializer);
store.checkAndPutResource(path2, t, StringEntity.serializer);
fail("write conflict should trigger IllegalStateException");
} catch (WriteConflictException e) {
内容来源于网络,如有侵权,请联系作者删除!