コード例 #1
0
        /// <summary>
        /// Build Cloud from already Exist master container
        /// </summary>
        /// <param name="configure"></param>
        /// <param name="property"></param>
        public void buildExistMaster(global::Aneka.Runtime.Configuration configure, ContainerProperty property)
        {
            try
            {
                Uri uri = new Uri(configure.IndexServerUri);
                CloudWebPortal.Areas.Aneka.Models.Machine machine = db.Machines.Where(x => x.IP == uri.Host).First();
                Cloud cloud = new Cloud();
                Master master = new Master();
                if (property.Status == ContainerStatus.Started)
                {
                    IContainerManagerProxy containerProxy = ProxyCreator.CreateContainerManagerProxy();
                    NodeInfo nodeInfo = containerProxy.GetNodeInfo(uri.ToString());
                    if (nodeInfo != null)
                    {
                        master.Services = new List<Service>();
                        foreach (String serviceName in nodeInfo.GetServices())
                        {
                            foreach (Service serviceFromDB in db.Services.ToList())
                            {
                                if (serviceFromDB.SpringSegmentXML.Contains(serviceName))
                                    master.Services.Add(serviceFromDB);
                            }
                        }
                    }
                }

                master.DisplayName = configure.IndexServerUri;
                master.isInstalled = true;
                master.Port = configure.Port;
                master.AnekaContainerID = property.Id;
                master.Cost = (int)configure.Cost;
                cloud.CloudName = configure.Name;

                db.Masters.Add(master);
                machine.Masters.Add(master);
                db.SaveChanges();

                db.Clouds.Add(cloud);
                cloud.Master = master;
                db.SaveChanges();

                try
                {
                    //Get already exist users
                    Uri masterUri = new Uri(ContainersManagement.GetContainerUri(machine.IP, master.Port));
                    global::Aneka.Security.UserCredentials adminLogin = new global::Aneka.Security.UserCredentials("Administrator", String.Empty);
                    AnekaUsersManagement anekaUsersManagement = new AnekaUsersManagement(masterUri, adminLogin);
                    List<CloudUserAccount> cloudUserAccounts = anekaUsersManagement.getAllUsersFromTheCloud();
                    foreach (CloudUserAccount account in cloudUserAccounts)
                    {
                        if (account.Password == "")
                            account.Password = "******";
                        account.Clouds = new List<Cloud>();
                        account.Clouds.Add(cloud);
                        db.CloudUserAccounts.Add(account);
                        db.SaveChanges();
                    }
                }
                catch (Exception)
                {

                }
                finally
                {
                    FinishedMasterActivity(cloud.CloudId);
                }

            }
            catch (Exception)
            {
            }
        }
コード例 #2
0
        /// <summary>
        /// Build Cloud from its information in the database
        /// </summary>
        /// <param name="cloudID">CloudID</param>
        public void CreateCloud(int cloudID)
        {
            Cloud cloud = db.Clouds.Find(cloudID);

            try
            {
                CloudWebPortal.Areas.Aneka.Models.Machine machine = machineLookupFromMasterId(cloud.Master.MasterId);
                Master master = cloud.Master;

                DaemonProbeResult result = new DaemonProbeResult(DaemonProbeStatus.Unknown, null);
                if (machine.StatusEnum == DaemonProbeStatus.ServiceStarted)
                    result = new DaemonProbeResult(DaemonProbeStatus.ServiceStarted, null);
                else
                    return;

                global::Aneka.PAL.Management.Model.Machine AnekaMachine = machineManagment.ToAnekaPALMachine(machine);

                byte[] key = global::Aneka.Security.Cryptography.AESCryptoUtil.GenerateKey();
                String NewSecuritySharedKey = Convert.ToBase64String(key);
               // String NewSecuritySharedKey = "whM2IcwXiQzmVbDyvOnOmPxgUS6WRp+VKVYuThtVuiM=";

                String containerId = CreateContainer(machine.Daemon.Directory,
                    machine.IP,
                    machine.Daemon.Port,
                    master.Port,
                    true,
                    cloud.CloudName,
                    master.Cost,
                    NewSecuritySharedKey,
                    machine.SoftwareAppliances,
                    master.Services,
                    AnekaMachine.DaemonUri,
                    null, //Only for worker
                    null, //Only for worker
                    cloud.DBConnectionString,//Only for master
                    cloud.Master.MasterFailoverBackupURI);//Only for master

                Master masterFromDB = db.Masters.Find(cloud.Master.MasterId);
                masterFromDB.AnekaContainerID = containerId;
                db.SaveChanges();

                Cloud cloudFromDB = db.Clouds.Find(cloudID);
                cloudFromDB.SecuritySharedKey = NewSecuritySharedKey;
                db.SaveChanges();

                //Get already exist users
                Uri masterUri = new Uri(ContainersManagement.GetContainerUri(machine.IP, master.Port));
                global::Aneka.Security.UserCredentials adminLogin = new global::Aneka.Security.UserCredentials("Administrator", String.Empty);
                AnekaUsersManagement anekaUsersManagement = new AnekaUsersManagement(masterUri, adminLogin);
                List<CloudUserAccount> cloudUserAccounts = anekaUsersManagement.getAllUsersFromTheCloud();
                foreach (CloudUserAccount account in cloudUserAccounts)
                {
                    if (account.Password == "")
                        account.Password = "******";
                    account.Clouds = new List<Cloud>();
                    account.Clouds.Add(cloud);
                    db.CloudUserAccounts.Add(account);
                    db.SaveChanges();
                }

                FinishedMasterActivity(cloud.CloudId);
            }
            catch (Exception ex)
            {
                Master masterFromDB = db.Masters.Find(cloud.Master.MasterId);
                masterFromDB.StatusEnum = global::Aneka.UI.Configuration.ProbeStatus.Error;
                masterFromDB.ProgressMesage = "Error while creating master container: " + ex;
                masterFromDB.isInProgress = false;
                db.SaveChanges();
            }
        }