use of com.hortonworks.registries.storage.exception.StorageException in project streamline by hortonworks.
the class StreamCatalogService method addOrUpdateTopologyComponentBundle.
public TopologyComponentBundle addOrUpdateTopologyComponentBundle(Long id, TopologyComponentBundle topologyComponentBundle, java.io.File bundleJar) throws ComponentConfigException, IOException {
topologyComponentBundle.getTopologyComponentUISpecification().validate();
loadTransformationClassForBundle(topologyComponentBundle, bundleJar);
if (!topologyComponentBundle.getBuiltin()) {
topologyComponentBundle.setBundleJar(getTopologyComponentBundleJarName(topologyComponentBundle));
try (InputStream is = new FileInputStream(bundleJar)) {
uploadFileToStorage(is, topologyComponentBundle.getBundleJar());
}
}
TopologyComponentBundle existing = new TopologyComponentBundle();
existing.setId(id);
existing = this.dao.get(existing.getStorableKey());
if (!existing.getBuiltin()) {
try {
deleteFileFromStorage(existing.getBundleJar());
} catch (IOException e) {
if (!topologyComponentBundle.getBuiltin()) {
deleteFileFromStorage(topologyComponentBundle.getBundleJar());
}
throw e;
}
}
try {
topologyComponentBundle.setId(id);
topologyComponentBundle.setTimestamp(System.currentTimeMillis());
this.dao.addOrUpdate(topologyComponentBundle);
} catch (StorageException e) {
if (!topologyComponentBundle.getBuiltin()) {
deleteFileFromStorage(topologyComponentBundle.getBundleJar());
}
throw e;
}
return topologyComponentBundle;
}
use of com.hortonworks.registries.storage.exception.StorageException in project registry by hortonworks.
the class AbstractStorable method toMap.
/**
* Default implementation that will read all the instance variable names using API and
* get the value by calling getter method (POJO) convention on it.
*
* Sometimes for JDBC to work we need an extra layer of transformation , for example see the implementation
* in {@code DataSource} which defines a field of type @{code Type} which is enum and not a primitive type as expected
* by the JDBC layer, you can call this method and override the fields that needs transformation.
*
* @return the map
*/
public Map<String, Object> toMap() {
Set<String> instanceVariableNames = ReflectionHelper.getFieldNamesToTypes(this.getClass()).keySet();
Map<String, Object> fieldToVal = new HashMap<>();
for (String fieldName : instanceVariableNames) {
try {
Object val = ReflectionHelper.invokeGetter(fieldName, this);
fieldToVal.put(fieldName, val);
if (LOG.isTraceEnabled()) {
LOG.trace("toMap: Adding fieldName {} = {} ", fieldName, val);
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new StorageException(e);
}
}
return fieldToVal;
}
use of com.hortonworks.registries.storage.exception.StorageException in project registry by hortonworks.
the class InMemoryStorageManager method update.
@Override
public void update(Storable storable) {
String namespace = storable.getNameSpace();
PrimaryKey pk = storable.getPrimaryKey();
if (!storageMap.containsKey(namespace)) {
throw new StorageException("Row could not be updated");
}
storageMap.get(namespace).put(pk, storable);
}
Aggregations