@SuppressWarnings("unchecked") private Map<String, String> reloadSourceTableExdAt(String path) throws IOException { Map<String, String> attrs = Maps.newHashMap(); ResourceStore store = getStore(); InputStream is = store.getResource(path); if (is == null) { logger.warn("Failed to get table exd info from " + path); return null; } try { attrs.putAll(JsonUtil.readValue(is, HashMap.class)); } finally { if (is != null) is.close(); } // parse table identity from file name String file = path; if (file.indexOf("/") > -1) { file = file.substring(file.lastIndexOf("/") + 1); } String tableIdentity = file.substring(0, file.length() - MetadataConstants.FILE_SURFIX.length()).toUpperCase(); srcTableExdMap.putLocal(tableIdentity, attrs); return attrs; }
public void saveTableExd(String tableId, Map<String, String> tableExdProperties) throws IOException { if (tableId == null) { throw new IllegalArgumentException("tableId couldn't be null"); } TableDesc srcTable = srcTableMap.get(tableId); if (srcTable == null) { throw new IllegalArgumentException("Couldn't find Source Table with identifier: " + tableId); } String path = TableDesc.concatExdResourcePath(tableId); ByteArrayOutputStream os = new ByteArrayOutputStream(); JsonUtil.writeValueIndent(os, tableExdProperties); os.flush(); InputStream is = new ByteArrayInputStream(os.toByteArray()); getStore().putResource(path, is, System.currentTimeMillis()); os.close(); is.close(); srcTableExdMap.putLocal(tableId, tableExdProperties); }
private ProjectInstance reloadProjectAt(String path) throws IOException { ResourceStore store = getStore(); ProjectInstance projectInstance = store.getResource(path, ProjectInstance.class, PROJECT_SERIALIZER); if (projectInstance == null) { logger.warn("reload project at path:" + path + " not found, this:" + this.toString()); return null; } projectInstance.init(); projectMap.putLocal(projectInstance.getName(), projectInstance); clearL2Cache(); return projectInstance; }
private TableDesc reloadSourceTableAt(String path) throws IOException { ResourceStore store = getStore(); TableDesc t = store.getResource(path, TableDesc.class, TABLE_SERIALIZER); if (t == null) { logger.error("Didn't load table at " + path); return null; } t.init(); String tableIdentity = t.getIdentity(); srcTableMap.putLocal(tableIdentity, t); return t; }
/** * Reload IIDesc from resource store It will be triggered by an desc update * event. * * @param name * @throws IOException */ public IIDesc reloadIIDesc(String name) throws IOException { // Save Source String path = IIDesc.getIIDescResourcePath(name); // Reload the IIDesc IIDesc ndesc = loadIIDesc(path); // Here replace the old one iiDescMap.putLocal(ndesc.getName(), ndesc); return ndesc; }
/** * Reload CubeDesc from resource store It will be triggered by an desc * update event. * * @param name * @throws IOException */ public CubeDesc reloadCubeDesc(String name) throws IOException { // Save Source String path = CubeDesc.getCubeDescResourcePath(name); // Reload the CubeDesc CubeDesc ndesc = loadCubeDesc(path); // Here replace the old one cubeDescMap.putLocal(ndesc.getName(), ndesc); return ndesc; }
private DataModelDesc reloadDataModelDescAt(String path) { ResourceStore store = getStore(); try { DataModelDesc dataModelDesc = store.getResource(path, DataModelDesc.class, MODELDESC_SERIALIZER); dataModelDesc.init(this.getAllTablesMap()); dataModelDescMap.putLocal(dataModelDesc.getName(), dataModelDesc); return dataModelDesc; } catch (IOException e) { throw new IllegalStateException("Error to load" + path, e); } }
private synchronized IIInstance loadIIInstance(String path) throws IOException { ResourceStore store = getStore(); logger.debug("Loading IIInstance " + store.getReadableResourcePath(path)); IIInstance IIInstance = null; try { IIInstance = store.getResource(path, IIInstance.class, II_SERIALIZER); IIInstance.setConfig(config); if (StringUtils.isBlank(IIInstance.getName())) throw new IllegalStateException("IIInstance name must not be blank"); iiMap.putLocal(IIInstance.getName(), IIInstance); for (IISegment segment : IIInstance.getSegments()) { usedStorageLocation.add(segment.getName()); } return IIInstance; } catch (Exception e) { logger.error("Error during load ii instance " + path, e); return null; } }
private synchronized CubeInstance loadCubeInstance(String path) throws IOException { ResourceStore store = getStore(); CubeInstance cubeInstance; try { cubeInstance = store.getResource(path, CubeInstance.class, CUBE_SERIALIZER); cubeInstance.setConfig(config); if (StringUtils.isBlank(cubeInstance.getName())) throw new IllegalStateException("CubeInstance name must not be blank, at " + path); if (cubeInstance.getDescriptor() == null) throw new IllegalStateException("CubeInstance desc not found '" + cubeInstance.getDescName() + "', at " + path); final String cubeName = cubeInstance.getName(); cubeMap.putLocal(cubeName, cubeInstance); for (CubeSegment segment : cubeInstance.getSegments()) { usedStorageLocation.put(cubeName, segment.getStorageLocationIdentifier()); } return cubeInstance; } catch (Exception e) { logger.error("Error during load cube instance " + path, e); return null; } }
private void reloadAllIIDesc() throws IOException { ResourceStore store = getStore(); logger.info("Reloading all II desc from folder " + store.getReadableResourcePath(ResourceStore.II_DESC_RESOURCE_ROOT)); iiDescMap.clear(); List<String> paths = store.collectResourceRecursively(ResourceStore.II_DESC_RESOURCE_ROOT, MetadataConstants.FILE_SURFIX); for (String path : paths) { logger.info("loading II Desc from path" + path); IIDesc desc; try { desc = loadIIDesc(path); } catch (Exception e) { logger.error("Error loading II desc " + path, e); continue; } if (!path.equals(desc.getResourcePath())) { logger.error("Skip suspicious desc at " + path + ", " + desc + " should be at " + desc.getResourcePath()); continue; } if (iiDescMap.containsKey(desc.getName())) { logger.error("Dup IIDesc name '" + desc.getName() + "' on path " + path); continue; } iiDescMap.putLocal(desc.getName(), desc); } logger.debug("Loaded " + iiDescMap.size() + " II desc(s)"); }
private void reloadAllCubeDesc() throws IOException { ResourceStore store = getStore(); logger.info("Reloading Cube Metadata from folder " + store.getReadableResourcePath(ResourceStore.CUBE_DESC_RESOURCE_ROOT)); cubeDescMap.clear(); List<String> paths = store.collectResourceRecursively(ResourceStore.CUBE_DESC_RESOURCE_ROOT, MetadataConstants.FILE_SURFIX); for (String path : paths) { CubeDesc desc; try { desc = loadCubeDesc(path); } catch (Exception e) { logger.error("Error loading cube desc " + path, e); continue; } if (path.equals(desc.getResourcePath()) == false) { logger.error("Skip suspicious desc at " + path + ", " + desc + " should be at " + desc.getResourcePath()); continue; } if (cubeDescMap.containsKey(desc.getName())) { logger.error("Dup CubeDesc name '" + desc.getName() + "' on path " + path); continue; } cubeDescMap.putLocal(desc.getName(), desc); } logger.debug("Loaded " + cubeDescMap.size() + " Cube(s)"); }
public void saveTableExd(String tableId, Map<String, String> tableExdProperties) throws IOException { if (tableId == null) { throw new IllegalArgumentException("tableId couldn't be null"); } TableDesc srcTable = srcTableMap.get(tableId); if (srcTable == null) { throw new IllegalArgumentException("Couldn't find Source Table with identifier: " + tableId); } String path = TableDesc.concatExdResourcePath(tableId); ByteArrayOutputStream os = new ByteArrayOutputStream(); JsonUtil.writeValueIndent(os, tableExdProperties); os.flush(); InputStream is = new ByteArrayInputStream(os.toByteArray()); getStore().putResource(path, is, System.currentTimeMillis()); os.close(); is.close(); srcTableExdMap.putLocal(tableId, tableExdProperties); }
private TableDesc reloadSourceTableAt(String path) throws IOException { ResourceStore store = getStore(); TableDesc t = store.getResource(path, TableDesc.class, TABLE_SERIALIZER); if (t == null) { logger.error("Didn't load table at " + path); return null; } t.init(); String tableIdentity = t.getIdentity(); srcTableMap.putLocal(tableIdentity, t); return t; }
private ProjectInstance reloadProjectAt(String path) throws IOException { ResourceStore store = getStore(); ProjectInstance projectInstance = store.getResource(path, ProjectInstance.class, PROJECT_SERIALIZER); if (projectInstance == null) { logger.warn("reload project at path:" + path + " not found, this:" + this.toString()); return null; } projectInstance.init(); projectMap.putLocal(projectInstance.getName(), projectInstance); clearL2Cache(); return projectInstance; }
/** * Reload IIDesc from resource store It will be triggered by an desc update * event. * * @param name * @throws IOException */ public IIDesc reloadIIDescLocal(String name) throws IOException { // Save Source String path = IIDesc.getIIDescResourcePath(name); // Reload the IIDesc IIDesc ndesc = loadIIDesc(path); // Here replace the old one iiDescMap.putLocal(ndesc.getName(), ndesc); return ndesc; }
private DataModelDesc reloadDataModelDescAt(String path) { ResourceStore store = getStore(); try { DataModelDesc dataModelDesc = store.getResource(path, DataModelDesc.class, MODELDESC_SERIALIZER); dataModelDesc.init(this.getAllTablesMap()); dataModelDescMap.putLocal(dataModelDesc.getName(), dataModelDesc); return dataModelDesc; } catch (IOException e) { throw new IllegalStateException("Error to load" + path, e); } }
/** * Reload StreamingConfig from resource store It will be triggered by an desc * update event. * * @param name * @throws IOException */ public StreamingConfig reloadStreamingConfigLocal(String name) throws IOException { // Save Source String path = StreamingConfig.concatResourcePath(name); // Reload the StreamingConfig StreamingConfig ndesc = loadStreamingConfigAt(path); // Here replace the old one streamingMap.putLocal(ndesc.getName(), ndesc); return ndesc; }
private synchronized IIInstance reloadIILocalAt(String path) throws IOException { ResourceStore store = getStore(); logger.debug("Loading IIInstance " + store.getReadableResourcePath(path)); IIInstance ii = null; try { ii = store.getResource(path, IIInstance.class, II_SERIALIZER); ii.setConfig(config); if (StringUtils.isBlank(ii.getName())) throw new IllegalStateException("IIInstance name must not be blank"); iiMap.putLocal(ii.getName(), ii); for (IISegment segment : ii.getSegments()) { usedStorageLocation.put(ii.getName().toUpperCase(), segment.getStorageLocationIdentifier()); } return ii; } catch (Exception e) { logger.error("Error during load ii instance " + path, e); return null; } }
private synchronized CubeInstance loadCubeInstance(String path) throws IOException { ResourceStore store = getStore(); CubeInstance cubeInstance; try { cubeInstance = store.getResource(path, CubeInstance.class, CUBE_SERIALIZER); cubeInstance.setConfig(config); if (StringUtils.isBlank(cubeInstance.getName())) throw new IllegalStateException("CubeInstance name must not be blank, at " + path); if (cubeInstance.getDescriptor() == null) throw new IllegalStateException("CubeInstance desc not found '" + cubeInstance.getDescName() + "', at " + path); final String cubeName = cubeInstance.getName(); cubeMap.putLocal(cubeName, cubeInstance); for (CubeSegment segment : cubeInstance.getSegments()) { usedStorageLocation.put(cubeName, segment.getStorageLocationIdentifier()); } return cubeInstance; } catch (Exception e) { logger.error("Error during load cube instance " + path, e); return null; } }
/** * Reload CubeDesc from resource store It will be triggered by an desc * update event. * * @param name * @throws IOException */ public CubeDesc reloadCubeDesc(String name) throws IOException { // Save Source String path = CubeDesc.getCubeDescResourcePath(name); // Reload the CubeDesc CubeDesc ndesc = loadCubeDesc(path); // Here replace the old one cubeDescMap.putLocal(ndesc.getName(), ndesc); Cuboid.reloadCache(ndesc.getName()); return ndesc; }