~tritone-team/tritone/eucalyptus

« back to all changes in this revision

Viewing changes to clc/modules/core/conf/scripts/Import_152.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:
1
1
 
2
2
import java.security.*;
 
3
 
3
4
import javax.crypto.spec.*;
4
5
import org.bouncycastle.jce.provider.BouncyCastleProvider;
5
6
import com.eucalyptus.util.EntityWrapper;
6
7
import com.eucalyptus.util.EucalyptusCloudException;
7
8
import com.eucalyptus.util.EntityWrapper;
 
9
import com.eucalyptus.util.SubDirectory;
 
10
import com.eucalyptus.util.WalrusProperties;
8
11
import com.eucalyptus.auth.CredentialProvider;
9
12
import com.eucalyptus.util.EntityWrapper;
10
13
import com.eucalyptus.util.EucalyptusCloudException;
49
52
import edu.ucsb.eucalyptus.cloud.ws.WalrusControl;
50
53
import edu.ucsb.eucalyptus.ic.StorageController;
51
54
import com.eucalyptus.util.StorageProperties;
52
 
 
53
 
//baseDir = "/disk1/import"
54
 
//targetDir = "/disk1/import"
 
55
import com.eucalyptus.config.Configuration;
 
56
import com.eucalyptus.config.ClusterConfiguration;
 
57
import com.eucalyptus.config.WalrusConfiguration;
 
58
import com.eucalyptus.config.StorageControllerConfiguration;
 
59
 
 
60
import java.io.File;
 
61
import java.net.URI;
 
62
import com.eucalyptus.util.DatabaseUtil;
 
63
import edu.ucsb.eucalyptus.cloud.entities.StorageInfo;
 
64
import edu.ucsb.eucalyptus.cloud.entities.WalrusInfo;
 
65
import edu.ucsb.eucalyptus.cloud.ws.WalrusControl;
 
66
import com.eucalyptus.auth.util.EucaKeyStore;
 
67
import com.eucalyptus.auth.util.Hashes.Digest;
 
68
import java.security.cert.X509Certificate;
 
69
import com.eucalyptus.auth.X509Cert;
 
70
import com.eucalyptus.auth.ClusterCredentials;
 
71
 
55
72
baseDir = "${System.getenv('EUCALYPTUS')}/var/lib/eucalyptus/db";
56
73
targetDir = baseDir;
57
74
targetDbPrefix= "eucalyptus"
79
96
System.setProperty("euca.home",System.getenv("EUCALYPTUS"))
80
97
System.setProperty("euca.var.dir","${System.getenv('EUCALYPTUS')}/var/lib/eucalyptus/")
81
98
System.setProperty("euca.log.dir", "${System.getenv('EUCALYPTUS')}/var/log/eucalyptus/")
 
99
Component c = Component.db
82
100
System.setProperty("euca.db.host", "jdbc:hsqldb:file:${targetDir}/${targetDbPrefix}")
 
101
 
 
102
def getDbPass() {
 
103
  Credentials.init();
 
104
  EucaKeyStore keyStore = EucaKeyStore.getCleanInstance();
 
105
  KeyPair kp = keyStore.getKeyPair("eucalyptus", "eucalyptus");
 
106
  PrivateKey pk = kp.getPrivate();
 
107
  Signature signer = Signature.getInstance( "SHA256withRSA" );
 
108
  signer.initSign( pk );
 
109
  signer.update( "eucalyptus".getBytes( ) );
 
110
  byte[] sig = signer.sign( );
 
111
  return Hashes.bytesToHex( sig );
 
112
}
 
113
 
83
114
System.setProperty("euca.db.password", "${System.getenv('EUCALYPTUS_DB')}");
84
115
System.setProperty("euca.log.level", 'INFO');
85
116
 
 
117
def vtunPassFile = new File("${System.getenv('EUCALYPTUS')}/var/lib/eucalyptus/keys/vtunpass");
 
118
vtunPassFile.write("${System.getenv('EUCALYPTUS_DB')}");
 
119
 
86
120
["${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
121
new File(it).write("CREATE SCHEMA PUBLIC AUTHORIZATION DBA\n" + 
88
122
          "CREATE USER SA PASSWORD \"" + System.getProperty( "euca.db.password" ) + "\"\n" +
243
277
  }
244
278
}
245
279
 
246
 
dbVolumes.rows("SELECT * FROM SNAPSHOT").each{
247
 
  println "Adding snapshot: ${it.DISPLAYNAME}"
248
 
  
249
 
  EntityWrapper<Snapshot> dbSnap = SnapshotManager.getEntityWrapper( );
250
 
  try {
251
 
    Snapshot s = new Snapshot(it.USERNAME,it.DISPLAYNAME);
252
 
    s.setBirthday(it.BIRTHDAY);
253
 
    s.setState(State.valueOf(it.STATE));
254
 
    s.setParentVolume(it.PARENTVOLUME);
255
 
    dbSnap.add(s);
256
 
    dbSnap.commit();
257
 
  } catch (Throwable t) {
258
 
    t.printStackTrace();
259
 
    dbSnap.rollback();
260
 
  }
261
 
}
262
 
 
263
280
db.rows('SELECT * FROM BUCKETS').each{
264
281
  println "Adding bucket: ${it.BUCKET_NAME}"
265
282
 
308
325
      //Do bucket object stuff here.
309
326
      EntityWrapper<ObjectInfo> dbObject = WalrusControl.getEntityWrapper();
310
327
      try {
311
 
        ObjectInfo objectInfo = new ObjectInfo(it.BUCKET_NAME, obj.OBJECT_NAME);
 
328
        ObjectInfo objectInfo = new ObjectInfo(it.BUCKET_NAME, obj.OBJECT_KEY);
312
329
        objectInfo.setObjectName(obj.OBJECT_NAME);
313
330
        objectInfo.setOwnerId(obj.OWNER_ID);
314
331
        objectInfo.setGlobalRead(obj.GLOBAL_READ);
315
332
        objectInfo.setGlobalWrite(obj.GLOBAL_WRITE);
316
333
        objectInfo.setGlobalReadACP(obj.GLOBAL_READ_ACP);
317
334
        objectInfo.setGlobalWriteACP(obj.GLOBAL_WRITE_ACP);
 
335
        objectInfo.setSize(obj.SIZE);
318
336
        objectInfo.setEtag(obj.ETAG);
319
337
        objectInfo.setLastModified(new Date());
320
338
        objectInfo.setStorageClass(obj.STORAGE_CLASS);
 
339
        objectInfo.setContentType("");
 
340
        objectInfo.setContentDisposition("");
321
341
        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 ->
322
342
        println "--> grant: ${obj.OBJECT_NAME}/${grant.USER_ID}"
323
343
          GrantInfo grantInfo = new GrantInfo();
396
416
                s.setScName(StorageProperties.SC_LOCAL_NAME);
397
417
                s.setUserName(it.SNAPSHOT_USER_NAME);
398
418
                s.setVolumeId(it.VOLUME_NAME);
399
 
                s.setStatus(it.STATUS);
 
419
                s.setStatus(StorageProperties.Status.pending.toString());
400
420
                s.setStartTime(new Date());
401
 
                s.setProgress(it.PROGRESS);
 
421
                s.setProgress("0");
402
422
                dbSnap.add(s);
403
423
                dbSnap.commit();
404
424
          } catch (Throwable t) {
449
469
  }
450
470
}
451
471
 
 
472
def clusterName = "testCluster";
 
473
 
452
474
db.rows('SELECT * FROM CLUSTERS').each{ 
453
 
  println "CLUSTER: name=${it.CLUSTER_NAME} host=${it.CLUSTER_HOST} port=${it.CLUSTER_PORT}"
454
 
}
 
475
  println "Adding CLUSTER: name=${it.CLUSTER_NAME} host=${it.CLUSTER_HOST} port=${it.CLUSTER_PORT}"
 
476
  clusterName = it.CLUSTER_NAME;
 
477
  EntityWrapper<ClusterConfiguration> dbClusterConfig = Configuration.getEntityWrapper();
 
478
  try {
 
479
    ClusterConfiguration clusterConfig = new ClusterConfiguration(it.CLUSTER_NAME, it.CLUSTER_HOST, it.CLUSTER_PORT);
 
480
    dbClusterConfig.add(clusterConfig);
 
481
    dbClusterConfig.commit();
 
482
  } catch (Throwable t) {
 
483
        t.printStackTrace();
 
484
        dbClusterConfig.rollback();
 
485
  }
 
486
}
 
487
 
 
488
X509Cert certInfo = new X509Cert("cc-" + clusterName);
 
489
certInfo.setPemCertificate(System.getenv('EUCALYPTUS_CLUSTER_CERT'))
 
490
X509Cert ncCertInfo = new X509Cert("nc-" + clusterName);
 
491
ncCertInfo.setPemCertificate(System.getenv('EUCALYPTUS_NODE_CERT'))
 
492
ClusterCredentials clusterCreds = new ClusterCredentials(clusterName);
 
493
clusterCreds.setClusterCertificate(certInfo);
 
494
clusterCreds.setNodeCertificate(ncCertInfo);
 
495
EntityWrapper<X509Cert> dbCert = Credentials.getEntityWrapper();
 
496
dbCert.add(certInfo);
 
497
dbCert.add(ncCertInfo);
 
498
EntityWrapper<ClusterCredentials> dbClusterCreds = dbCert.recast(ClusterCredentials.class);
 
499
dbClusterCreds.add(clusterCreds);
 
500
dbCert.commit();
 
501
 
 
502
dbVolumes.rows("SELECT * FROM SNAPSHOT").each{
 
503
          println "Adding snapshot: ${it.DISPLAYNAME}"
 
504
          
 
505
          EntityWrapper<Snapshot> dbSnap = SnapshotManager.getEntityWrapper( );
 
506
          try {
 
507
            Snapshot s = new Snapshot(it.USERNAME,it.DISPLAYNAME);
 
508
            s.setBirthday(it.BIRTHDAY);
 
509
            s.setState(State.valueOf(it.STATE));
 
510
            s.setParentVolume(it.PARENTVOLUME);
 
511
            s.setCluster(clusterName);
 
512
            s.setMappedState(StorageProperties.Status.pending.toString());
 
513
            dbSnap.add(s);
 
514
            dbSnap.commit();
 
515
          } catch (Throwable t) {
 
516
            t.printStackTrace();
 
517
            dbSnap.rollback();
 
518
          }
 
519
}
 
520
 
 
521
def getInterface() {
 
522
  def oldEucaConf = new File("${System.getenv('EUCALYPTUS')}/etc/eucalyptus/eucalyptus.conf-1.5");
 
523
    oldEucaConf.text.find(/VNET_INTERFACE="(.*)"/) { fullline, iface ->      
 
524
          return iface.toString()
 
525
    }
 
526
}
 
527
 
 
528
db.rows('SELECT * FROM SYSTEM_INFO').each{
 
529
        URI uri = new URI(it.SYSTEM_INFO_STORAGE_URL)
 
530
        println "Adding Walrus: name=walrus host=${uri.getHost()} port=${uri.getPort()}"
 
531
        EntityWrapper<WalrusConfiguration> dbWalrusConfig = Configuration.getEntityWrapper();
 
532
        EntityWrapper<WalrusInfo> dbWalrus = WalrusControl.getEntityWrapper();
 
533
        try {
 
534
          WalrusConfiguration walrusConfig = new WalrusConfiguration("walrus", uri.getHost(), uri.getPort());
 
535
          dbWalrusConfig.add(walrusConfig);
 
536
          dbWalrusConfig.commit();
 
537
          try {
 
538
            WalrusInfo walrusInfo = dbWalrus.getUnique(new WalrusInfo());
 
539
            walrusInfo.setStorageDir(it.SYSTEM_STORAGE_DIR)
 
540
            walrusInfo.setStorageMaxBucketsPerUser(it.SYSTEM_STORAGE_MAX_BUCKETS_PER_USER)
 
541
            walrusInfo.setStorageMaxBucketSizeInMB((int)(it.SYSTEM_STORAGE_MAX_BUCKET_SIZE_MB / WalrusProperties.M))
 
542
            walrusInfo.setStorageMaxCacheSizeInMB((int)(it.SYSTEM_STORAGE_CACHE_SIZE_MB / WalrusProperties.M))
 
543
            walrusInfo.setStorageMaxTotalSnapshotSizeInGb(it.SYSTEM_STORAGE_SNAPSHOT_SIZE_GB)
 
544
          } catch(Throwable t) {                 
 
545
            WalrusInfo walrusInfo = new WalrusInfo(WalrusProperties.NAME,
 
546
                          it.SYSTEM_STORAGE_DIR,
 
547
                          it.SYSTEM_STORAGE_MAX_BUCKETS_PER_USER,
 
548
                          (int)(it.SYSTEM_STORAGE_MAX_BUCKET_SIZE_MB / WalrusProperties.M),
 
549
                          (int)(it.SYSTEM_STORAGE_CACHE_SIZE_MB / WalrusProperties.M),
 
550
                          it.SYSTEM_STORAGE_SNAPSHOT_SIZE_GB)
 
551
            dbWalrus.add(walrusInfo)        
 
552
          }
 
553
          dbWalrus.commit();
 
554
        } catch(Throwable t) {
 
555
          t.printStackTrace();
 
556
          dbWalrusConfig.rollback();
 
557
          dbWalrus.rollback();
 
558
        }
 
559
        println "Adding SC: name=StorageController-local host=${uri.getHost()} port=${uri.getPort()}"
 
560
        EntityWrapper<StorageControllerConfiguration> dbSCConfig = Configuration.getEntityWrapper();
 
561
        EntityWrapper<StorageInfo> dbSC = StorageController.getEntityWrapper();         
 
562
        try {
 
563
          StorageControllerConfiguration storageConfig = new StorageControllerConfiguration(clusterName, uri.getHost(), uri.getPort());
 
564
          dbSCConfig.add(storageConfig);
 
565
          dbSCConfig.commit();
 
566
          StorageInfo storageInfo = new StorageInfo(StorageProperties.SC_LOCAL_NAME,
 
567
                          it.SYSTEM_STORAGE_MAX_VOLUME_SIZE_GB,
 
568
                          getInterface(),
 
569
                          it.SYSTEM_STORAGE_VOLUME_SIZE_GB,
 
570
                          it.SYSTEM_STORAGE_VOLUMES_DIR,
 
571
                          false);
 
572
          dbSC.add(storageInfo);
 
573
          dbSC.commit();
 
574
    } catch(Throwable t) {
 
575
          t.printStackTrace();
 
576
          dbSCConfig.rollback();
 
577
          dbSC.rollback();
 
578
        }
 
579
}
 
580
 
 
581
//flush
 
582
DatabaseUtil.closeAllEMFs();
 
583
//the db will not sync to disk even after a close in some cases. Wait a bit.
 
584
Thread.sleep(5000);
 
 
b'\\ No newline at end of file'