49
52
import edu.ucsb.eucalyptus.cloud.ws.WalrusControl;
50
53
import edu.ucsb.eucalyptus.ic.StorageController;
51
54
import com.eucalyptus.util.StorageProperties;
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;
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;
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}")
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 );
83
114
System.setProperty("euca.db.password", "${System.getenv('EUCALYPTUS_DB')}");
84
115
System.setProperty("euca.log.level", 'INFO');
117
def vtunPassFile = new File("${System.getenv('EUCALYPTUS')}/var/lib/eucalyptus/keys/vtunpass");
118
vtunPassFile.write("${System.getenv('EUCALYPTUS_DB')}");
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" +
308
325
//Do bucket object stuff here.
309
326
EntityWrapper<ObjectInfo> dbObject = WalrusControl.getEntityWrapper();
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();
472
def clusterName = "testCluster";
452
474
db.rows('SELECT * FROM CLUSTERS').each{
453
println "CLUSTER: name=${it.CLUSTER_NAME} host=${it.CLUSTER_HOST} port=${it.CLUSTER_PORT}"
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();
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) {
484
dbClusterConfig.rollback();
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);
502
dbVolumes.rows("SELECT * FROM SNAPSHOT").each{
503
println "Adding snapshot: ${it.DISPLAYNAME}"
505
EntityWrapper<Snapshot> dbSnap = SnapshotManager.getEntityWrapper( );
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());
515
} catch (Throwable t) {
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()
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();
534
WalrusConfiguration walrusConfig = new WalrusConfiguration("walrus", uri.getHost(), uri.getPort());
535
dbWalrusConfig.add(walrusConfig);
536
dbWalrusConfig.commit();
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)
554
} catch(Throwable t) {
556
dbWalrusConfig.rollback();
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();
563
StorageControllerConfiguration storageConfig = new StorageControllerConfiguration(clusterName, uri.getHost(), uri.getPort());
564
dbSCConfig.add(storageConfig);
566
StorageInfo storageInfo = new StorageInfo(StorageProperties.SC_LOCAL_NAME,
567
it.SYSTEM_STORAGE_MAX_VOLUME_SIZE_GB,
569
it.SYSTEM_STORAGE_VOLUME_SIZE_GB,
570
it.SYSTEM_STORAGE_VOLUMES_DIR,
572
dbSC.add(storageInfo);
574
} catch(Throwable t) {
576
dbSCConfig.rollback();
582
DatabaseUtil.closeAllEMFs();
583
//the db will not sync to disk even after a close in some cases. Wait a bit.
b'\\ No newline at end of file'