Search in sources :

Example 11 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class ObjManager method close.

public int close(String bucketName, String path, Metadata mt) throws ResourceNotFoundException {
    Bucket bt;
    try {
        bt = getBucket(bucketName);
    } catch (SQLException ex) {
        throw new ResourceNotFoundException("Bucket(" + bucketName + ") not exist ! >" + ex);
    }
    if (bt == null)
        throw new ResourceNotFoundException("Bucket(" + bucketName + ") not exist!");
    try {
        Metadata mtd = dbm.selectSingleObject(bt.getDiskPoolId(), bucketName, path);
        if (!bt.getVersioning().equalsIgnoreCase("Enabled"))
            dbm.deleteObject(bucketName, path, "null");
    } catch (ResourceNotFoundException ex) {
    }
    if (!obmCache.isDiskSeparatedAndValid(bt.getDiskPoolId(), mt)) {
        String err = String.format("Bucket : %s key : %s disk information pdiskid : %s rdiskid : %s is not separated or not exist in the syystem", bucketName, path, mt.getPrimaryDisk().getId(), mt.isReplicaExist() ? mt.getReplicaDisk().getId() : "");
        logger.debug(err);
        throw new InvalidParameterException(err);
    }
    // System.out.format("[close ] bucket : %s path : %s objid : %s\n", mt.getBucket(), mt.getPath(), mt.getObjId());
    // to update last modified time to now
    mt.updateLastmodified();
    return dbm.insertObject(mt);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) SQLException(java.sql.SQLException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 12 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class ObjManager method replaceDisk.

/**
 * Replace replica disk with new one after recovery
 * @param bucketName  bucket name
 * @param objid       object id
 * @param pdiskid     primary disk id
 * @param rdiskid     new replica disk id
 * @return -1 if it is failed, 0 if nothing is updated or 1 if it is successful
 * @throws ResourceNotFoundException if the disk provided is not valid or exist in the system
 */
public int replaceDisk(String bucketName, String objid, String pdiskid, String rdiskid) throws ResourceNotFoundException {
    String diskpoolid;
    DISK primary;
    DISK replica;
    Bucket bt;
    try {
        bt = getBucket(bucketName);
    } catch (SQLException ex) {
        throw new ResourceNotFoundException("unable to get buckt " + bucketName + " in the system!");
    }
    diskpoolid = bt.getDiskPoolId();
    primary = obmCache.getDiskWithId(diskpoolid, pdiskid);
    replica = obmCache.getDiskWithId(diskpoolid, rdiskid);
    logger.debug(" PRIMARY > " + pdiskid + ", " + primary + " REPLICA >" + rdiskid + " ," + replica);
    Metadata md = new Metadata();
    md.setObjid(objid);
    md.setPrimaryDisk(primary);
    md.setReplicaDISK(replica);
    return dbm.updateDisks(md);
}
Also used : SQLException(java.sql.SQLException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 13 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class ObjManager method createCopy.

/**
 * Return the same primary and replica disk to copy the the object and reside in the same osd.
 * @param bucket bucket name
 * @param toBucket bucket name of destination
 * @param from  key of the source metadata
 * @param to  key of the destination metadata
 * @param versionId  version id of the source object
 * @return a basics of metadata object with allocated disk information
 * @throws IOException
 * @throws AllServiceOfflineException
 * @throws ResourceNotFoundException
 */
public Metadata createCopy(String bucket, String from, String versionId, String toBucket, String to) throws IOException, AllServiceOfflineException, ResourceNotFoundException, SQLException {
    Metadata mt;
    Metadata cpy_mt;
    Bucket bt = getBucket(bucket);
    mt = dbm.selectSingleObject(bt.getDiskPoolId(), bucket, from, versionId);
    if (mt == null)
        throw new ResourceNotFoundException("Bucket(" + bucket + ")  and key(" + from + ") not exist!");
    cpy_mt = new Metadata(toBucket, to);
    cpy_mt.setPrimaryDisk(mt.getPrimaryDisk());
    cpy_mt.setReplicaCount(bt.getReplicaCount());
    if (mt.isReplicaExist())
        cpy_mt.setReplicaDISK(mt.getReplicaDisk());
    return cpy_mt;
}
Also used : ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 14 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class ObjManager method close.

/**
 * Store the metadata for the file associated with path
 * @param bucketName
 * @param path path or key of the metadata is going to be stored
 * @param etag
 * @param meta
 * @param tag
 * @param pdskPath primary disk path
 * @param rdskPath replica disk path
 * @return
 * @throws InvalidParameterException
 * @throws ResourceNotFoundException
 */
public int close(String bucketName, String path, String etag, String meta, String tag, long size, String acl, String pdskPath, String rdskPath, String versionId, String deleteMarker) throws InvalidParameterException, ResourceNotFoundException {
    Metadata mt;
    Bucket bt;
    DISK pdsk;
    DISK rdsk;
    boolean isreplicaExist;
    mt = new Metadata(bucketName, path);
    mt.set(etag, tag, meta, acl, size);
    mt.setVersionId(versionId, deleteMarker, true);
    try {
        bt = this.getBucket(bucketName);
    } catch (SQLException ex) {
        throw new ResourceNotFoundException("Bucket(" + bucketName + ") not exist ! >" + ex);
    }
    if (bt == null)
        throw new ResourceNotFoundException("Bucket(" + bucketName + ") not exist!");
    pdsk = obmCache.getDiskWithPath(bt.getDiskPoolId(), pdskPath);
    isreplicaExist = false;
    mt.setPrimaryDisk(pdsk);
    if (rdskPath != null) {
        if (!rdskPath.isEmpty()) {
            rdsk = obmCache.getDiskWithPath(bt.getDiskPoolId(), rdskPath);
            isreplicaExist = true;
            mt.setReplicaDISK(rdsk);
        }
    }
    mt.setReplicaCount(bt.getReplicaCount());
    return this.close(bucketName, path, mt);
/*try {
            if (path.isEmpty())
               throw new InvalidParameterException("empty path not allowed!"); 
            
            if (!obmCache.validateDisk(bt.getDiskPoolId(), "", pdskPath))
                throw new InvalidParameterException("primary disk("+pdskPath+") not exist in the system!");
            
            if (isreplicaExist){
                if (!obmCache.validateDisk(bt.getDiskPoolId(), "", rdskPath)){
                    logger.debug("bucket : {} path : {} there replica disk provided", bucketName, path);
                    //throw new InvalidParameterException("Replica disk not exist in the system!");
                }
            }
            
            mt = dbm.selectSingleObject(bt.getDiskPoolId(), bucketName, path);
            if (!bt.getVersioning().equalsIgnoreCase("Enabled"))
                dbm.deleteObject(bucketName, path, "null");
            mt.setPrimaryDisk(pdsk);
            if (isreplicaExist)
                mt.setReplicaDISK(rdsk);
            mt.setEtag(etag);
            mt.setTag(tag);
            mt.setMeta(meta); 
            mt.setSize(size);
            mt.setAcl(acl);
            mt.setVersionId(versionId, deleteMarker, true);
        } catch(ResourceNotFoundException ex){
            // create meta
            mt = new Metadata(bucketName, path, etag, meta, tag, size, acl, pdsk.getId(), 
                    pdsk.getPath(), isreplicaExist?  rdsk.getId() : "", 

                    isreplicaExist ? rdsk.getPath() : "", versionId, deleteMarker); 
 
            mt.setVersionId(versionId, deleteMarker, true);
        }
    
        // inseret to db
        return dbm.insertObject(mt);*/
}
Also used : SQLException(java.sql.SQLException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 15 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class ObjManager method _open.

private Metadata _open(String bucket, String path, String versionId) throws ResourceNotFoundException {
    Metadata mt;
    Bucket bt;
    try {
        bt = getBucket(bucket);
    } catch (SQLException ex) {
        throw new ResourceNotFoundException("Bucket(" + bucket + ") failed to reterive in the system due to :" + ex);
    }
    if (bt == null) {
        throw new ResourceNotFoundException("Bucket(" + bucket + ") not exist in the system!");
    }
    if (versionId == null)
        mt = dbm.selectSingleObject(bt.getDiskPoolId(), bucket, path);
    else
        mt = dbm.selectSingleObject(bt.getDiskPoolId(), bucket, path, versionId);
    mt.setReplicaCount(bt.getReplicaCount());
    return mt;
}
Also used : SQLException(java.sql.SQLException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)36 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)11 SQLException (java.sql.SQLException)11 GWException (com.pspace.ifs.ksan.gw.exception.GWException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)8 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)8 XMLStreamException (javax.xml.stream.XMLStreamException)8 IOException (java.io.IOException)6 InvalidParameterException (java.security.InvalidParameterException)5 Document (org.bson.Document)5 AllServiceOfflineException (com.pspace.ifs.ksan.objmanager.ObjManagerException.AllServiceOfflineException)4 Iterator (java.util.Iterator)4 Bucket (com.pspace.ifs.ksan.objmanager.Bucket)3 ArrayList (java.util.ArrayList)3 FindIterable (com.mongodb.client.FindIterable)2 MQResponse (com.pspace.ifs.ksan.mq.MQResponse)2 ObjManager (com.pspace.ifs.ksan.objmanager.ObjManager)2 ObjManagerUtil (com.pspace.ifs.ksan.objmanager.ObjManagerUtil)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2