Search in sources :

Example 6 with StorageException

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;
}
Also used : DigestInputStream(java.security.DigestInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) StorageException(com.hortonworks.registries.storage.exception.StorageException) FileInputStream(java.io.FileInputStream) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Example 7 with StorageException

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;
}
Also used : HashMap(java.util.HashMap) StorageException(com.hortonworks.registries.storage.exception.StorageException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with StorageException

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);
}
Also used : PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) StorageException(com.hortonworks.registries.storage.exception.StorageException)

Aggregations

StorageException (com.hortonworks.registries.storage.exception.StorageException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 PrimaryKey (com.hortonworks.registries.storage.PrimaryKey)2 AlreadyExistsException (com.hortonworks.registries.storage.exception.AlreadyExistsException)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 DigestInputStream (java.security.DigestInputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 ParserException (com.hortonworks.registries.common.exception.ParserException)1 IncompatibleSchemaException (com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException)1 InvalidSchemaBranchVersionMapping (com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchVersionMapping)1 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)1 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)1 OrderByField (com.hortonworks.registries.storage.OrderByField)1 Storable (com.hortonworks.registries.storage.Storable)1 StorableKey (com.hortonworks.registries.storage.StorableKey)1 IllegalQueryParameterException (com.hortonworks.registries.storage.exception.IllegalQueryParameterException)1 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)1