Search in sources :

Example 1 with ResourceNotFoundException

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

the class DBPerformanceTest method createBucket.

static void createBucket() {
    try {
        ObjManager om = new ObjManager();
        try {
            System.out.println("bucketName :>" + bucket);
            om.createBucket(bucket, userName, userName, "acl", "", "");
        } catch (ResourceNotFoundException ex) {
            Logger.getLogger(DBPerformanceTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (ResourceAlreadyExistException ex) {
        System.out.println("Bucket already exist!");
    } catch (Exception ex) {
        System.out.println("OBJMANAGER INIT ERROR : " + ex);
    }
}
Also used : ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) ObjManager(com.pspace.ifs.ksan.objmanager.ObjManager) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) IOException(java.io.IOException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) InvalidParameterException(java.security.InvalidParameterException) AllServiceOfflineException(com.pspace.ifs.ksan.objmanager.ObjManagerException.AllServiceOfflineException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 2 with ResourceNotFoundException

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

the class FSCK method checkEachObject.

/*public void howtouse(String progName){
        System.out.format("%s FSCK --action=<check|fix> --type=<Server|Disk|Object> --serverid=<OsdServerId> --diskid=<OsdDiskId> --objid=<ObjectId>\n"
                + "  Where: "
                + " --type  : server if the whole server failed, Disk if a disk failed and otherwise Object if a single object failed ", progName);
    }
    private int parseArgs(String [] args){
        String argInLower;
        String tmp;
        for(String arg : args){
            argInLower = arg.toLowerCase();
            if (argInLower.startsWith("--action")){ 
                tmp =argInLower.split("=")[1];
                if (tmp.equalsIgnoreCase("fix"))
                    isFixOn = true;      
            }
            if (argInLower.startsWith("--type")) {
                type = argInLower.split("=")[1].toLowerCase();
            }
            if (argInLower.startsWith("--serverid")) serverId = argInLower.split("=")[1];
            if (argInLower.startsWith("--diskid")) diskid = argInLower.split("=")[1];
            if (argInLower.startsWith("--objid")) objid = argInLower.split("=")[1];
        }
        
        return 0;
    }
    
    private DISK getNewDisk(String bucketName, String pdpath, String pdiskid) throws ResourceNotFoundException, AllServiceOfflineException{
        return obmu.allocReplicaDisk(bucketName, pdpath, pdiskid);
    }
    
    private int getObjectAttr(){
        return 0;
    }
    
    private int replicate(String objid, DISK from, DISK to) throws Exception{
        String bindingKey="recoverObject";
        String msg2send = String.format("{ from: %s to : %s }", from.toString(), to.toString());
        
        mqSender.send(msg2send, bindingKey);
        return 0;
    }
    
    private int repairObject(Metadata mt, String path, String diskid){
        obmu.updateObject(mt.getBucket(), mt.getObjId(),  mt, 1);
        return 0;
    }*/
private long checkEachObject(String bucketName, String diskid) {
    List<Metadata> list;
    long offset = 0;
    long numObjects = 100;
    long job_done = 0;
    int ret;
    ret = objm.startJob();
    if (ret != 0)
        return 0;
    do {
        list = obmu.listObjects(bucketName, diskid, 1, offset, numObjects);
        if (list == null)
            return 0;
        if (list.isEmpty())
            return 0;
        Iterator<Metadata> it = list.iterator();
        while (it.hasNext()) {
            totalChecked++;
            if (!objm.ISJobRunning()) {
                totalFixed = totalFixed + job_done;
                objm.updateNumberObjectsProcessed(totalChecked, totalFixed);
                return job_done;
            }
            Metadata mt = it.next();
            try {
                if (!mt.isReplicaExist()) {
                    System.out.format(">> Bucket : %s path : %s pdisk : %s rdisk : %s \n", mt.getBucket(), mt.getPath(), mt.isPrimaryExist() ? mt.getPrimaryDisk().getPath() : " Empty", mt.isReplicaExist() ? mt.getReplicaDisk().getPath() : " Empty");
                    if (!checkOnly)
                        objm.moveObject(bucketName, mt.getObjId(), mt.getPrimaryDisk().getId());
                    job_done++;
                }
            } catch (ResourceNotFoundException | AllServiceOfflineException ex) {
                System.out.format(" Bucket : %s path : %s pdisk : %s \n", mt.getBucket(), mt.getPath(), mt.isPrimaryExist() ? mt.getPrimaryDisk().getPath() : "");
            }
        }
        offset = offset + numObjects;
        System.out.println("----------------------------------------------------------->" + job_done);
    } while (list.size() == numObjects);
    totalFixed = totalFixed + job_done;
    objm.updateNumberObjectsProcessed(totalChecked, totalFixed);
    objm.finishedJob();
    return job_done;
}
Also used : AllServiceOfflineException(com.pspace.ifs.ksan.objmanager.ObjManagerException.AllServiceOfflineException) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 3 with ResourceNotFoundException

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

the class MongoDataRepository method selectSingleObjectInternal.

private Metadata selectSingleObjectInternal(String bucketName, String objId, String versionId) throws ResourceNotFoundException {
    MongoCollection<Document> objects;
    FindIterable fit;
    Metadata mt;
    objects = database.getCollection(bucketName);
    if (versionId.isEmpty())
        fit = objects.find(Filters.and(eq(OBJID, objId), eq(LASTVERSION, true)));
    else
        fit = objects.find(Filters.and(eq(OBJID, objId), eq(VERSIONID, versionId)));
    Bucket bt = obmCache.getBucketFromCache(bucketName);
    if (bt == null)
        throw new ResourceNotFoundException("There is not bucket with a bucket name " + bucketName + " and contain object with objid " + objId);
    Document doc = (Document) fit.first();
    if (doc == null)
        throw new ResourceNotFoundException("There is not object with a bucket name " + bucketName + " and objid " + objId);
    long lastModified = doc.getLong(LASTMODIFIED);
    String key = (String) doc.get(OBJKEY);
    String etag = doc.getString(ETAG);
    String meta = doc.getString(META);
    String tag = doc.getString(TAG);
    long size = doc.getLong(SIZE);
    String acl = doc.getString(ACL);
    String versionid = doc.getString(VERSIONID);
    String deleteMarker = doc.getString(DELETEMARKER);
    boolean lastversion = doc.getBoolean(LASTVERSION);
    String pdiskId = doc.getString(PDISKID);
    DISK pdsk = pdiskId != null ? obmCache.getDiskWithId(bt.getDiskPoolId(), pdiskId) : new DISK();
    String rdiskId = doc.getString(RDISKID);
    DISK rdsk;
    if (rdiskId == null)
        rdsk = new DISK();
    else if (rdiskId.isEmpty())
        rdsk = new DISK();
    else
        rdsk = obmCache.getDiskWithId(bt.getDiskPoolId(), rdiskId);
    mt = new Metadata(bucketName, key);
    mt.set(etag, tag, meta, acl, size);
    mt.setPrimaryDisk(pdsk);
    mt.setReplicaDISK(rdsk);
    mt.setLastModified(lastModified);
    // mt.setSize(size);
    mt.setVersionId(versionid, deleteMarker, lastversion);
    return mt;
}
Also used : FindIterable(com.mongodb.client.FindIterable) Document(org.bson.Document) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 4 with ResourceNotFoundException

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

the class MongoDataRepository method parseBucket.

private Bucket parseBucket(String bucketName, Document doc) throws ResourceNotFoundException, SQLException {
    if (doc == null)
        throw new ResourceNotFoundException("There is not bucket with a name " + bucketName);
    String diskPoolId = doc.getString(DISKPOOLID);
    String bucketId = doc.getString(BUCKETID);
    String userId = doc.getString(USERID);
    String web = doc.getString(WEB);
    String acl = doc.getString(ACL);
    String cors = doc.getString(CORS);
    String lifecycle = doc.getString(LIFECYCLE);
    String access = doc.getString(ACCESS);
    String tagging = doc.getString(TAGGING);
    String replication = doc.getString(REPLICATION);
    int replicaCount = doc.getInteger(REPLICACOUNT);
    Date createTime;
    try {
        String createTimeStr = doc.getString(CREATETIME);
        if (createTimeStr == null)
            createTime = new Date(0);
        else
            createTime = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(createTimeStr);
    } catch (ParseException ex) {
        createTime = new Date(0);
    }
    String versioning = doc.getString(VERSIONING);
    String mfdelete = doc.getString(MFADELETE);
    Bucket bt = new Bucket(bucketName, bucketId, diskPoolId);
    bt.setUserId(userId);
    bt.setWeb(web);
    bt.setAccess(access);
    bt.setAcl(acl);
    bt.setCors(cors);
    bt.setLifecycle(lifecycle);
    bt.setTagging(tagging);
    bt.setReplication(replication);
    bt.setCreateTime(createTime);
    bt.setVersioning(versioning, mfdelete);
    bt.setReplicaCount(replicaCount);
    // System.out.println(">>" + bt);
    return bt;
}
Also used : ParseException(java.text.ParseException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 5 with ResourceNotFoundException

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

the class MongoDataRepository method loadBucketList.

@Override
public void loadBucketList() {
    Bucket bt;
    FindIterable<Document> fit = buckets.find();
    Iterator it = fit.iterator();
    while ((it.hasNext())) {
        try {
            Document doc = (Document) it.next();
            String bucketName = (String) doc.get(BUCKETNAME);
            bt = parseBucket(bucketName, doc);
            obmCache.setBucketInCache(bt);
        } catch (ResourceNotFoundException | SQLException ex) {
            Logger.getLogger(MongoDataRepository.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Iterator(java.util.Iterator) Document(org.bson.Document) 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