Package com.cloud.bridge.model

Examples of com.cloud.bridge.model.SHost


      }
    }
   
    public void testHosts() {
    Session session;
    SHost shost;
    MHost mhost;
    MHostMount hostMount;

      session = CloudSessionFactory.getInstance().openSession();
      try {
        Transaction txn = session.beginTransaction();
        shost = new SHost();
        shost.setHost("Storage host1");
        shost.setUserOnHost("root");
        shost.setUserPassword("password");
      shost.setExportRoot("/");
        session.save(shost);
       
        mhost = new MHost();
        mhost.setHostKey("1");
        mhost.setHost("management host1");
View Full Code Here


public class ModelTestCase extends BaseTestCase {
    protected final static Logger logger = Logger.getLogger(ModelTestCase.class);

    public void testSHost() {
    SHost host;
   
    // create the record
    Session session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setExportRoot("/");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      session.saveOrUpdate(host);
      txn.commit();
    } finally {
      session.close();
    }
    Assert.assertTrue(host.getId() != 0);
   
    // retrive the record
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = (SHost)session.get(SHost.class, (long)host.getId());
      txn.commit();
     
      Assert.assertTrue(host.getHost().equals("localhost"));
      Assert.assertTrue(host.getUserOnHost().equals("root"));
      Assert.assertTrue(host.getUserPassword().equals("password"));
     
      logger.info("Retrived record, host:" + host.getHost()
          + ", user: " + host.getUserOnHost()
          + ", password: " + host.getUserPassword());
     
    } finally {
      session.close();
    }
   
    // delete the record
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = (SHost)session.get(SHost.class, (long)host.getId());
      session.delete(host);
      txn.commit();
    } finally {
      session.close();
    }
   
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = (SHost)session.get(SHost.class, (long)host.getId());
      txn.commit();
     
      Assert.assertTrue(host == null);
    } finally {
      session.close();
View Full Code Here

      session.close();
    }
    }
   
    public void testSBucket() {
      SHost host;
      SBucket bucket;
      Session session;
     
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      host.setExportRoot("/");
     
      bucket = new SBucket();
      bucket.setName("Bucket");
      bucket.setOwnerCanonicalId("OwnerId-dummy");
      bucket.setCreateTime(new Date());
     
      host.getBuckets().add(bucket);
      bucket.setShost(host);
     
      session.save(host);
      session.save(bucket);
      txn.commit();
    } finally {
      session.close();
    }
   
    long bucketId = bucket.getId();
   
    // load bucket
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      bucket = (SBucket)session.get(SBucket.class, bucketId);
      txn.commit();
     
      Assert.assertTrue(bucket.getShost().getHost().equals("localhost"));
      Assert.assertTrue(bucket.getName().equals("Bucket"));
      Assert.assertTrue(bucket.getOwnerCanonicalId().equals("OwnerId-dummy"));
    } finally {
      session.close();
    }
   
    // delete the bucket
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      bucket = (SBucket)session.get(SBucket.class, bucketId);
      session.delete(bucket);
     
      host = (SHost)session.get(SHost.class, host.getId());
      session.delete(host);
      txn.commit();
    } finally {
      session.close();
    }
View Full Code Here

      session.close();
    }
    }
   
    public void testSObject() {
      SHost host;
      SBucket bucket;
      Session session;
      SObject sobject;
     
      // setup
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      host.setExportRoot("/");
     
      bucket = new SBucket();
      bucket.setName("Bucket");
      bucket.setOwnerCanonicalId("OwnerId-dummy");
      bucket.setCreateTime(new Date());
      bucket.setShost(host);
      host.getBuckets().add(bucket);
     
      sobject = new SObject();
      sobject.setNameKey("ObjectNameKey");
      sobject.setOwnerCanonicalId("OwnerId-dummy");
      sobject.setCreateTime(new Date());
      sobject.setBucket(bucket);
      bucket.getObjectsInBucket().add(sobject);
     
      session.save(host);
      session.save(bucket);
      session.save(sobject);
      txn.commit();
     
    } finally {
      session.close();
    }
   
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      sobject = (SObject)session.get(SObject.class, sobject.getId());
      txn.commit();
      Assert.assertTrue(sobject.getBucket().getName().equals("Bucket"));
      Assert.assertTrue(sobject.getNameKey().equals("ObjectNameKey"));
      Assert.assertTrue(sobject.getOwnerCanonicalId().equals("OwnerId-dummy"));
    } finally {
      session.close();
    }

    // test delete cascade
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      bucket = (SBucket)session.get(SBucket.class, bucket.getId());
      session.delete(bucket);
     
      host = (SHost)session.get(SHost.class, host.getId());
      session.delete(host);
      txn.commit();
    } finally {
      session.close();
    }
View Full Code Here

public class ModelTestCase extends BaseTestCase {
    protected final static Logger logger = Logger.getLogger(ModelTestCase.class);

    public void testSHost() {
    SHost host;
   
    // create the record
    Session session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setExportRoot("/");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      session.saveOrUpdate(host);
      txn.commit();
    } finally {
      session.close();
    }
    Assert.assertTrue(host.getId() != 0);
   
    // retrive the record
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = (SHost)session.get(SHost.class, (long)host.getId());
      txn.commit();
     
      Assert.assertTrue(host.getHost().equals("localhost"));
      Assert.assertTrue(host.getUserOnHost().equals("root"));
      Assert.assertTrue(host.getUserPassword().equals("password"));
     
      logger.info("Retrived record, host:" + host.getHost()
          + ", user: " + host.getUserOnHost()
          + ", password: " + host.getUserPassword());
     
    } finally {
      session.close();
    }
   
    // delete the record
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = (SHost)session.get(SHost.class, (long)host.getId());
      session.delete(host);
      txn.commit();
    } finally {
      session.close();
    }
   
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = (SHost)session.get(SHost.class, (long)host.getId());
      txn.commit();
     
      Assert.assertTrue(host == null);
    } finally {
      session.close();
View Full Code Here

      session.close();
    }
    }
   
    public void testSBucket() {
      SHost host;
      SBucket bucket;
      Session session;
     
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      host.setExportRoot("/");
     
      bucket = new SBucket();
      bucket.setName("Bucket");
      bucket.setOwnerCanonicalId("OwnerId-dummy");
      bucket.setCreateTime(new Date());
     
      host.getBuckets().add(bucket);
      bucket.setShost(host);
     
      session.save(host);
      session.save(bucket);
      txn.commit();
    } finally {
      session.close();
    }
   
    long bucketId = bucket.getId();
   
    // load bucket
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      bucket = (SBucket)session.get(SBucket.class, bucketId);
      txn.commit();
     
      Assert.assertTrue(bucket.getShost().getHost().equals("localhost"));
      Assert.assertTrue(bucket.getName().equals("Bucket"));
      Assert.assertTrue(bucket.getOwnerCanonicalId().equals("OwnerId-dummy"));
    } finally {
      session.close();
    }
   
    // delete the bucket
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      bucket = (SBucket)session.get(SBucket.class, bucketId);
      session.delete(bucket);
     
      host = (SHost)session.get(SHost.class, host.getId());
      session.delete(host);
      txn.commit();
    } finally {
      session.close();
    }
View Full Code Here

      session.close();
    }
    }
   
    public void testSObject() {
      SHost host;
      SBucket bucket;
      Session session;
      SObject sobject;
     
      // setup
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      host.setExportRoot("/");
     
      bucket = new SBucket();
      bucket.setName("Bucket");
      bucket.setOwnerCanonicalId("OwnerId-dummy");
      bucket.setCreateTime(new Date());
      bucket.setShost(host);
      host.getBuckets().add(bucket);
     
      sobject = new SObject();
      sobject.setNameKey("ObjectNameKey");
      sobject.setOwnerCanonicalId("OwnerId-dummy");
      sobject.setCreateTime(new Date());
      sobject.setBucket(bucket);
      bucket.getObjectsInBucket().add(sobject);
     
      session.save(host);
      session.save(bucket);
      session.save(sobject);
      txn.commit();
     
    } finally {
      session.close();
    }
   
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      sobject = (SObject)session.get(SObject.class, sobject.getId());
      txn.commit();
      Assert.assertTrue(sobject.getBucket().getName().equals("Bucket"));
      Assert.assertTrue(sobject.getNameKey().equals("ObjectNameKey"));
      Assert.assertTrue(sobject.getOwnerCanonicalId().equals("OwnerId-dummy"));
    } finally {
      session.close();
    }

    // test delete cascade
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      bucket = (SBucket)session.get(SBucket.class, bucket.getId());
      session.delete(bucket);
     
      host = (SHost)session.get(SHost.class, host.getId());
      session.delete(host);
      txn.commit();
    } finally {
      session.close();
    }
View Full Code Here

      }
    }
   
    public void testHosts() {
    Session session;
    SHost shost;
    MHost mhost;
    MHostMount hostMount;

      session = CloudSessionFactory.getInstance().openSession();
      try {
        Transaction txn = session.beginTransaction();
        shost = new SHost();
        shost.setHost("Storage host1");
        shost.setUserOnHost("root");
        shost.setUserPassword("password");
      shost.setExportRoot("/");
        session.save(shost);
       
        mhost = new MHost();
        mhost.setHostKey("1");
        mhost.setHost("management host1");
View Full Code Here

   
  public Tuple<SHost, String> getBucketStorageHost(SBucket bucket)
  {
    MHostMountDao mountDao = new MHostMountDao();
   
    SHost shost = bucket.getShost();
    if(shost.getHostType() == SHost.STORAGE_HOST_TYPE_LOCAL) {
      return new Tuple<SHost, String>(shost, shost.getExportRoot());
    }
   
    MHostMount mount = mountDao.getHostMount(ServiceProvider.getInstance().getManagementHostId(), shost.getId());
    if(mount != null) {
      return new Tuple<SHost, String>(shost, mount.getMountPath());
    }

    // need to redirect request to other node
    throw new HostNotMountedException("Storage host " + shost.getHost() + " is not locally mounted");
  }
View Full Code Here

    }
   
    // To make things simple, only allow one local mounted storage root
    String localStorageRoot = ServiceProvider.getInstance().getStartupProperties().getProperty("storage.root");
    if(localStorageRoot != null) {
      SHost localSHost = shostDao.getLocalStorageHost(mhost.getId(), localStorageRoot);
      if(localSHost == null)
        throw new InternalErrorException("storage.root is configured but not initialized");
     
      S3BucketAdapter bucketAdapter =  getStorageHostBucketAdapter(localSHost);
      bucketAdapter.createContainer(localSHost.getExportRoot(),(null != overrideName ? overrideName : bucketName));
      return new Tuple<SHost, String>(localSHost, localStorageRoot);
    }
   
    throw new OutOfStorageException("No storage host is available");
  }
View Full Code Here

TOP

Related Classes of com.cloud.bridge.model.SHost

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.