~tritone-team/tritone/eucalyptus

« back to all changes in this revision

Viewing changes to clc/modules/core/conf/scripts/Import_150.groovy

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-12-01 21:09:28 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: james.westby@ubuntu.com-20091201210928-o2dvg0ubljhb0ft6
Tags: upstream-1.6.1~bzr1083
ImportĀ upstreamĀ versionĀ 1.6.1~bzr1083

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
import edu.ucsb.eucalyptus.cloud.ws.WalrusControl;
50
50
import edu.ucsb.eucalyptus.ic.StorageController;
51
51
import com.eucalyptus.util.StorageProperties;
 
52
import com.eucalyptus.config.Configuration;
 
53
import com.eucalyptus.config.ClusterConfiguration;
 
54
import com.eucalyptus.config.WalrusConfiguration;
 
55
import com.eucalyptus.config.StorageControllerConfiguration;
 
56
import java.net.URI;
 
57
import com.eucalyptus.util.DatabaseUtil;
 
58
import edu.ucsb.eucalyptus.cloud.entities.StorageInfo;
 
59
import edu.ucsb.eucalyptus.cloud.entities.WalrusInfo;
 
60
import edu.ucsb.eucalyptus.cloud.ws.WalrusControl;
 
61
import java.security.cert.X509Certificate;
 
62
import com.eucalyptus.auth.X509Cert;
 
63
import com.eucalyptus.auth.ClusterCredentials;
52
64
 
53
 
//baseDir = "/disk1/import"
54
 
//targetDir = "/disk1/import"
55
65
baseDir = "${System.getenv('EUCALYPTUS')}/var/lib/eucalyptus/db";
56
66
targetDir = baseDir;
57
67
targetDbPrefix= "eucalyptus"
83
93
System.setProperty("euca.db.password", "${System.getenv('EUCALYPTUS_DB')}");
84
94
System.setProperty("euca.log.level", 'INFO');
85
95
 
 
96
def vtunPassFile = new File("${System.getenv('EUCALYPTUS')}/var/lib/eucalyptus/keys/vtunpass");
 
97
vtunPassFile.write("${System.getenv('EUCALYPTUS_DB')}");
 
98
 
86
99
["${baseDir}/eucalyptus_general.script","${baseDir}/eucalyptus_images.script","${baseDir}/eucalyptus_auth.script","${baseDir}/eucalyptus_config.script","${baseDir}/eucalyptus_walrus.script","${baseDir}/eucalyptus_storage.script","${baseDir}/eucalyptus_dns.script"].each{
87
100
new File(it).write("CREATE SCHEMA PUBLIC AUTHORIZATION DBA\n" + 
88
101
          "CREATE USER SA PASSWORD \"" + System.getProperty( "euca.db.password" ) + "\"\n" +
240
253
  }
241
254
}
242
255
 
243
 
dbVolumes.rows("SELECT * FROM SNAPSHOT").each{
244
 
  println "Adding snapshot: ${it.DISPLAYNAME}"
245
 
  
246
 
  EntityWrapper<Snapshot> dbSnap = SnapshotManager.getEntityWrapper( );
247
 
  try {
248
 
    Snapshot s = new Snapshot(it.USERNAME,it.DISPLAYNAME);
249
 
    s.setBirthday(it.BIRTHDAY);
250
 
    s.setState(State.valueOf(it.STATE));
251
 
    s.setParentVolume(it.PARENTVOLUME);
252
 
    dbSnap.add(s);
253
 
    dbSnap.commit();
254
 
  } catch (Throwable t) {
255
 
    t.printStackTrace();
256
 
    dbSnap.rollback();
257
 
  }
258
 
}
259
 
 
260
256
db.rows('SELECT * FROM BUCKETS').each{
261
257
  println "Adding bucket: ${it.BUCKET_NAME}"
262
258
 
312
308
        objectInfo.setGlobalWrite(obj.GLOBAL_WRITE);
313
309
        objectInfo.setGlobalReadACP(obj.GLOBAL_READ_ACP);
314
310
        objectInfo.setGlobalWriteACP(obj.GLOBAL_WRITE_ACP);
 
311
        objectInfo.setSize(obj.SIZE);
315
312
        objectInfo.setEtag(obj.ETAG);
316
313
        objectInfo.setLastModified(new Date());
317
314
        objectInfo.setStorageClass(obj.STORAGE_CLASS);
 
315
        objectInfo.setContentType("");
 
316
        objectInfo.setContentDisposition("");
318
317
        db.rows("SELECT g.* FROM object_has_grants has_thing LEFT OUTER JOIN grants g on g.grant_id=has_thing.grant_id WHERE has_thing.object_id=${ obj.OBJECT_ID }").each{  grant ->
319
318
        println "--> grant: ${obj.OBJECT_NAME}/${grant.USER_ID}"
320
319
          GrantInfo grantInfo = new GrantInfo();
384
383
}
385
384
 
386
385
db.rows('SELECT * FROM SNAPSHOTS').each{ 
387
 
          println "Adding snapshit: ${it.SNAPSHOT_NAME}"
 
386
          println "Adding snapshot: ${it.SNAPSHOT_NAME}"
388
387
 
389
388
          EntityWrapper<VolumeInfo> dbSnap = StorageController.getEntityWrapper(); 
390
389
          try {
393
392
                s.setScName(StorageProperties.SC_LOCAL_NAME);
394
393
                s.setUserName(it.SNAPSHOT_USER_NAME);
395
394
                s.setVolumeId(it.VOLUME_NAME);
396
 
                s.setStatus(it.STATUS);
 
395
                s.setStatus(StorageProperties.Status.pending.toString());
397
396
                s.setStartTime(new Date());
 
397
                s.setProgress("0");
398
398
                dbSnap.add(s);
399
399
                dbSnap.commit();
400
400
          } catch (Throwable t) {
445
445
  }
446
446
}
447
447
 
 
448
 
 
449
def clusterName = "testCluster";
 
450
 
448
451
db.rows('SELECT * FROM CLUSTERS').each{ 
449
 
  println "CLUSTER: name=${it.CLUSTER_NAME} host=${it.CLUSTER_HOST} port=${it.CLUSTER_PORT}"
450
 
}
 
452
  println "Adding CLUSTER: name=${it.CLUSTER_NAME} host=${it.CLUSTER_HOST} port=${it.CLUSTER_PORT}"
 
453
  clusterName = it.CLUSTER_NAME;
 
454
  EntityWrapper<ClusterConfiguration> dbClusterConfig = Configuration.getEntityWrapper();
 
455
  try {
 
456
    ClusterConfiguration clusterConfig = new ClusterConfiguration(it.CLUSTER_NAME, it.CLUSTER_HOST, it.CLUSTER_PORT);
 
457
    dbClusterConfig.add(clusterConfig);
 
458
    dbClusterConfig.commit();
 
459
  } catch (Throwable t) {
 
460
        t.printStackTrace();
 
461
        dbClusterConfig.rollback();
 
462
  }
 
463
}
 
464
 
 
465
X509Cert certInfo = new X509Cert("cc-" + clusterName);
 
466
certInfo.setPemCertificate(System.getenv('EUCALYPTUS_CLUSTER_CERT'))
 
467
X509Cert ncCertInfo = new X509Cert("nc-" + clusterName);
 
468
ncCertInfo.setPemCertificate(System.getenv('EUCALYPTUS_NODE_CERT'))
 
469
ClusterCredentials clusterCreds = new ClusterCredentials(clusterName);
 
470
clusterCreds.setClusterCertificate(certInfo);
 
471
clusterCreds.setNodeCertificate(ncCertInfo);
 
472
EntityWrapper<X509Cert> dbCert = Credentials.getEntityWrapper();
 
473
dbCert.add(certInfo);
 
474
dbCert.add(ncCertInfo);
 
475
EntityWrapper<ClusterCredentials> dbClusterCreds = dbCert.recast(ClusterCredentials.class);
 
476
dbClusterCreds.add(clusterCreds);
 
477
dbCert.commit();
 
478
 
 
479
dbVolumes.rows("SELECT * FROM SNAPSHOT").each{
 
480
          println "Adding snapshot: ${it.DISPLAYNAME}"
 
481
          
 
482
          EntityWrapper<Snapshot> dbSnap = SnapshotManager.getEntityWrapper( );
 
483
          try {
 
484
            Snapshot s = new Snapshot(it.USERNAME,it.DISPLAYNAME);
 
485
            s.setBirthday(it.BIRTHDAY);
 
486
            s.setState(State.valueOf(it.STATE));
 
487
            s.setParentVolume(it.PARENTVOLUME);
 
488
            s.setCluster(clusterName);
 
489
            s.setMappedState(StorageProperties.Status.pending.toString());
 
490
            dbSnap.add(s);
 
491
            dbSnap.commit();
 
492
          } catch (Throwable t) {
 
493
            t.printStackTrace();
 
494
            dbSnap.rollback();
 
495
          }
 
496
        }
 
497
 
 
498
def getInterface() {
 
499
          def oldEucaConf = new File("${System.getenv('EUCALYPTUS')}/etc/eucalyptus/eucalyptus.conf-1.5");
 
500
            oldEucaConf.text.find(/VNET_INTERFACE="(.*)"/) { fullline, iface ->      
 
501
                  return iface.toString()
 
502
            }
 
503
}
 
504
 
 
505
db.rows('SELECT * FROM SYSTEM_INFO').each{
 
506
        URI uri = new URI(it.SYSTEM_INFO_STORAGE_URL)
 
507
        println "Adding Walrus: name=walrus host=${uri.getHost()} port=${uri.getPort()}"
 
508
        EntityWrapper<WalrusConfiguration> dbWalrusConfig = Configuration.getEntityWrapper();
 
509
        EntityWrapper<WalrusInfo> dbWalrus = WalrusControl.getEntityWrapper();
 
510
        try {
 
511
          WalrusConfiguration walrusConfig = new WalrusConfiguration("walrus", uri.getHost(), uri.getPort());
 
512
          dbWalrusConfig.add(walrusConfig);
 
513
          dbWalrusConfig.commit();
 
514
          try {
 
515
            WalrusInfo walrusInfo = dbWalrus.getUnique(new WalrusInfo());
 
516
            walrusInfo.setStorageDir(it.SYSTEM_STORAGE_DIR)
 
517
            walrusInfo.setStorageMaxBucketsPerUser(it.SYSTEM_STORAGE_MAX_BUCKETS_PER_USER)
 
518
            walrusInfo.setStorageMaxBucketSizeInMB((int)(it.SYSTEM_STORAGE_MAX_BUCKET_SIZE_MB / WalrusProperties.M))
 
519
            walrusInfo.setStorageMaxCacheSizeInMB((int)(it.SYSTEM_STORAGE_CACHE_SIZE_MB / WalrusProperties.M))
 
520
            walrusInfo.setStorageMaxTotalSnapshotSizeInGb(it.SYSTEM_STORAGE_SNAPSHOT_SIZE_GB)
 
521
          } catch(Throwable t) {                 
 
522
            WalrusInfo walrusInfo = new WalrusInfo(WalrusProperties.NAME,
 
523
                          it.SYSTEM_STORAGE_DIR,
 
524
                          it.SYSTEM_STORAGE_MAX_BUCKETS_PER_USER,
 
525
                          (int)(it.SYSTEM_STORAGE_MAX_BUCKET_SIZE_MB / WalrusProperties.M),
 
526
                          (int)(it.SYSTEM_STORAGE_CACHE_SIZE_MB / WalrusProperties.M),
 
527
                          it.SYSTEM_STORAGE_SNAPSHOT_SIZE_GB)
 
528
            dbWalrus.add(walrusInfo)        
 
529
          }
 
530
          dbWalrus.commit();
 
531
        } catch(Throwable t) {
 
532
          t.printStackTrace();
 
533
          dbWalrusConfig.rollback();
 
534
          dbWalrus.rollback();
 
535
        }
 
536
        println "Adding SC: name=StorageController-local host=${uri.getHost()} port=${uri.getPort()}"
 
537
        EntityWrapper<StorageControllerConfiguration> dbSCConfig = Configuration.getEntityWrapper();
 
538
        EntityWrapper<StorageInfo> dbSC = StorageController.getEntityWrapper();         
 
539
        try {
 
540
          StorageControllerConfiguration storageConfig = new StorageControllerConfiguration(clusterName, uri.getHost(), uri.getPort());
 
541
          dbSCConfig.add(storageConfig);
 
542
          dbSCConfig.commit();
 
543
          StorageInfo storageInfo = new StorageInfo(StorageProperties.SC_LOCAL_NAME,
 
544
                          it.SYSTEM_STORAGE_MAX_VOLUME_SIZE_GB,
 
545
                          getInterface(),
 
546
                          it.SYSTEM_STORAGE_VOLUME_SIZE_GB,
 
547
                          it.SYSTEM_STORAGE_VOLUMES_DIR,
 
548
                          false);
 
549
          dbSC.add(storageInfo);
 
550
          dbSC.commit();
 
551
    } catch(Throwable t) {
 
552
          t.printStackTrace();
 
553
          dbSCConfig.rollback();
 
554
          dbSC.rollback();
 
555
        }
 
556
}
 
557
 
 
558
//flush
 
559
DatabaseUtil.closeAllEMFs();
 
560
//the db will not sync to disk even after a close in some cases. Wait a bit.
 
561
Thread.sleep(5000);
 
 
b'\\ No newline at end of file'