Esempio n. 1
0
        public override sealed DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            DeploymentDetails ret = null;

            try
            {
                recommendedBranchIP = LockSerializationKey(initiationSource, recommendedBranchIP);
                if (recommendedBranchIP != null)
                {
                    ret = GenerateDeploymentDetailsSerializationVerified(listPreprocessResult, initiationSource, recommendedBranchIP);

                    if (ret == null)
                    {
                        lock (_Keys)
                        {
                            BoundKey binding = _Keys.Values.FirstOrDefault(i => i.InitiationSource.ToUpper() == initiationSource.ToUpper());
                            if (binding != null)
                            {
                                binding.InitiationSource = null;
                                binding.Assigned         = false;
                                binding.FileSize         = 0;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("KeyedDeploymentController.GenerateDeploymentDetails", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                ReleaseSerializationKey(initiationSource);
                ret = null;
            }

            return(ret);
        }
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            DeploymentDetails ret = null;

            try
            {
                if (LockSerializationKey(initiationSource))
                {
                    ret = GenerateDeploymentDetailsSerializationVerified(listPreprocessResult, initiationSource, recommendedBranchIP);

                    if (ret == null)
                    {
                        ReleaseSerializationKey(initiationSource, false);
                    }
                }
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("SerialDeploymentController.LockSerializationKey", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                ReleaseSerializationKey(initiationSource, false);
                ret = null;
            }

            return(ret);
        }
        public void RoundtripSerialization()
        {
            var deployment = new DeploymentDetails {
                Status  = "Failed",
                Targets = new[] {
                    new DeploymentTargetDetails(new ManagedResource(Borg, ResourceTypes.Host, "1")),
                    new DeploymentTargetDetails(new ManagedResource(Borg, ResourceTypes.Cluster, "2")),
                    new DeploymentTargetDetails(new ManagedResource(Borg, ResourceTypes.Environment, "3"))
                }
            };

            Assert.Equal(@"{
  ""status"": ""Failed"",
  ""targets"": [
    {
      ""resource"": ""borg:host\/1""
    },
    {
      ""resource"": ""borg:cluster\/2""
    },
    {
      ""resource"": ""borg:environment\/3""
    }
  ]
}", JsonObject.FromObject(deployment).ToString());

            var d2 = JsonObject.Parse(JsonObject.FromObject(deployment).ToString()).As <DeploymentDetails>();

            Assert.Equal("borg:host/1", d2.Targets[0].Resource.ToString());
        }
        public void RoundtripSerialization2()
        {
            var program = new ProgramInfo(1, 1, "carbon", "carbon", new SemanticVersion(1, 1, 1));

            var deployment = new DeploymentDetails(program, new[] {
                ManagedResource.Host(Borg, id: "1"),
                ManagedResource.Cluster(Borg, id: "2"),
                ManagedResource.Environment(Borg, id: "3")
            });

            Assert.Equal(@"{
  ""program"": {
    ""id"": 1,
    ""version"": ""1.1.1""
  },
  ""targets"": [
    {
      ""resource"": ""borg:host\/1""
    },
    {
      ""resource"": ""borg:cluster\/2""
    },
    {
      ""resource"": ""borg:environment\/3""
    }
  ]
}", JsonObject.FromObject(deployment).ToString());
        }
Esempio n. 5
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            DeploymentDetails ret = null;

            try
            {
                string dp = TemplateKVP.Keys.ToList().FirstOrDefault(i => i.Equals("[DestinationPath]", StringComparison.InvariantCultureIgnoreCase));
                if (dp == null)
                {
                    throw new Exception("No macro [DestinationPath] exists in this DeploymentController.");
                }

                TemplateKVP["[DestinationPath]"] = TemplateKVP[dp];

                InstructionSet clone = GetTemplateInstance(true);

                CustomizeInstructionSet(clone, TemplateKVP, recommendedBranchIP, initiationSource, true);

                return(new DeploymentDetails(clone, recommendedBranchIP));
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("BasicFileController.GenerateDeploymentDetails", new Exception(InstructionSetTemplate + ": " + initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
            }

            return(ret);
        }
            public void CopyFrom(DeploymentDetails source)
            {
                if (source != null)
                {
                    BranchIP               = source.BranchIP;
                    DeploymentManagerIP    = source.DeploymentManagerIP;
                    InitiationSource       = source.InitiationSource;
                    InstructionSetID       = source.InstructionSetID;
                    DeploymentControllerID = source.DeploymentControllerID;
                    SwitchboardRowID       = source.SwitchboardRowID;
                    DeploymentController   = source.DeploymentController;
                    Issued       = source.Issued;
                    Received     = source.Received;
                    Completed    = source.Completed;
                    LastModified = source.LastModified;

                    if (Completed > DateTime.MinValue)
                    {
                        ExecutionTime = (Completed - Received).TotalSeconds;
                    }
                    else if (Received > DateTime.MinValue)
                    {
                        ExecutionTime = (DateTime.UtcNow - Received).TotalSeconds;
                    }
                    else
                    {
                        ExecutionTime = (DateTime.UtcNow - Issued).TotalSeconds;
                    }

                    Exceptions = source.Exceptions.Count;
                }
            }
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            try
            {
                Dictionary <string, string> v = _QueryResults[initiationSource];

                if (v != null)
                {
                    _QueryResults.Remove(initiationSource);

                    System.Collections.Generic.Dictionary <string, string> kvp = TemplateKVP.ToDictionary(i => i.Key, i => i.Value);

                    foreach (string k in v.Keys)
                    {
                        kvp[k] = v[k];
                    }

                    DeploymentDetails ret = base.GenerateDeploymentDetails(listPreprocessResult, initiationSource, recommendedBranchIP, limitedToBranches);

                    CustomizeInstructionSet(ret.ISet, kvp, ret.BranchIP, initiationSource, false);

                    return(ret);
                }
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("SQLController.GenerateDeploymentDetails", new Exception(initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
            }

            return(null);
        }
Esempio n. 8
0
        public override void ExecutionComplete(DeploymentDetails details, List <Exception> exceptions)
        {
            try
            {
                base.ExecutionComplete(details, exceptions);
            }
            catch { }

            if (!_Ranges.ContainsKey(DeploymentControllerID))
            {
                lock (_Ranges)
                    if (!_Ranges.ContainsKey(DeploymentControllerID))
                    {
                        _Ranges[DeploymentControllerID] = new List <SizeRange>();
                    }
            }

            lock (_Ranges[DeploymentControllerID])
            {
                SizeRange range = _Ranges[DeploymentControllerID].FirstOrDefault(i => i.ActiveLoads.Exists(x => x.Loaded.Contains(details.InitiationSource)));
                if (range != null)
                {
                    lock (range)
                    {
                        SizeRange.Load rem = range.ActiveLoads.FirstOrDefault(z => z.Loaded.Contains(details.InitiationSource));
                        if (rem != null)
                        {
                            rem.Loaded.Remove(details.InitiationSource);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            DeploymentDetails dd = base.GenerateDeploymentDetails(listPreprocessResult, initiationSource, recommendedBranchIP, limitedToBranches);

            if (dd != null)
            {
                foreach (Instruction ins in dd.ISet.Instructions)
                {
                    foreach (PropertyInfo prop in ins.GetType().GetProperties().Where(p => p.PropertyType.IsSubclassOf(typeof(IAuthentication))))
                    {
                        IAuthentication a = prop.GetValue(ins) as IAuthentication;

                        if (a.VersionDescriptor.TypeName == "STEM.Surge.Azure.Authentication")
                        {
                            PropertyInfo i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "StorageConnectionString");
                            if (i != null)
                            {
                                string k = i.GetValue(a) as string;
                                if (String.IsNullOrEmpty(k))
                                {
                                    i.SetValue(a, Authentication.StorageConnectionString);
                                }
                            }
                        }
                    }
                }
            }

            return(dd);
        }
Esempio n. 10
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            try
            {
                TemplateKVP["[FtpServerAddress]"] = STEM.Sys.IO.Path.IPFromPath(PollerSourceString);
                TemplateKVP["[FtpServerPort]"]    = Port.ToString();

                DeploymentDetails dd = base.GenerateDeploymentDetails(listPreprocessResult, initiationSource, recommendedBranchIP, limitedToBranches);

                if (dd != null)
                {
                    foreach (Instruction ins in dd.ISet.Instructions)
                    {
                        foreach (PropertyInfo prop in ins.GetType().GetProperties().Where(p => p.PropertyType.IsSubclassOf(typeof(IAuthentication))))
                        {
                            IAuthentication a = prop.GetValue(ins) as IAuthentication;

                            if (a.VersionDescriptor.TypeName == "STEM.Surge.FTP.Authentication")
                            {
                                PropertyInfo i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "FTPPassword");
                                if (i != null)
                                {
                                    string k = i.GetValue(a) as string;
                                    if (String.IsNullOrEmpty(k))
                                    {
                                        i.SetValue(a, Authentication.FTPPassword);

                                        i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "FTPUser");
                                        if (i != null)
                                        {
                                            i.SetValue(a, Authentication.FTPUser);
                                        }

                                        i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "RequireCertificateValidation");
                                        if (i != null)
                                        {
                                            i.SetValue(a, Authentication.RequireCertificateValidation);
                                        }

                                        i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "UseTLS");
                                        if (i != null)
                                        {
                                            i.SetValue(a, Authentication.UseTLS);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(dd);
            }
            finally
            {
                TemplateKVP["[FtpServerAddress]"] = "Reserved";
                TemplateKVP["[FtpServerPort]"]    = "Reserved";
            }
        }
        public override void ExecutionComplete(DeploymentDetails details, List <Exception> exceptions)
        {
            base.ExecutionComplete(details, exceptions);

            XmlDoc doc = null;

            lock (_Assignments)
            {
                if (!_Assignments.ContainsKey(details.InstructionSetID))
                {
                    return;
                }

                doc = _Assignments[details.InstructionSetID];
                _Assignments.Remove(details.InstructionSetID);
            }

            if (exceptions == null || exceptions.Count == 0)
            {
                if (doc != null)
                {
                    lock (_Documents)
                        lock (doc)
                        {
                            if (!doc.Nodes.ContainsKey(details.InitiationSource))
                            {
                                return;
                            }

                            XElement e = doc.Nodes[details.InitiationSource];

                            doc.Nodes.Remove(details.InitiationSource);

                            e.Remove();

                            if (doc.OriginalLastWriteTime == File.GetLastWriteTimeUtc(doc.Filename))
                            {
                                doc.Document.Save(doc.Filename);

                                if (doc.Nodes.Count == 0)
                                {
                                    try
                                    {
                                        File.Delete(doc.Filename);
                                        _Documents.Remove(doc);
                                    }
                                    catch { }
                                }
                                else
                                {
                                    File.SetLastWriteTimeUtc(doc.Filename, doc.OriginalLastWriteTime);
                                }
                            }
                        }
                }
            }
        }
Esempio n. 12
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            try
            {
                TemplateKVP["[ContainerName]"] = STEM.Sys.IO.Path.FirstTokenOfPath(initiationSource).ToLower();

                DeploymentDetails dd = base.GenerateDeploymentDetails(listPreprocessResult, initiationSource, recommendedBranchIP, limitedToBranches);

                if (dd != null)
                {
                    foreach (Instruction ins in dd.ISet.Instructions)
                    {
                        foreach (PropertyInfo prop in ins.GetType().GetProperties().Where(p => p.PropertyType.IsSubclassOf(typeof(IAuthentication))))
                        {
                            IAuthentication a = prop.GetValue(ins) as IAuthentication;

                            if (a.VersionDescriptor.TypeName == "STEM.Surge.GCS.Authentication")
                            {
                                PropertyInfo i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "GoogleCredentialFile");
                                if (i != null)
                                {
                                    string k = i.GetValue(a) as string;
                                    if (String.IsNullOrEmpty(k))
                                    {
                                        i.SetValue(a, Authentication.GoogleCredentialFile);
                                    }
                                }

                                i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "ProjectName");
                                if (i != null)
                                {
                                    string k = i.GetValue(a) as string;
                                    if (String.IsNullOrEmpty(k))
                                    {
                                        i.SetValue(a, Authentication.ProjectName);
                                    }
                                }
                            }
                        }
                    }
                }

                return(dd);
            }
            finally
            {
                TemplateKVP["[ContainerName]"] = "Reserved";
            }
        }
Esempio n. 13
0
        public override void ExecutionComplete(DeploymentDetails details, List <Exception> exceptions)
        {
            base.ExecutionComplete(details, exceptions);

            List <string> locks = STEM.Sys.State.Containers.Session[details.InstructionSetID.ToString()] as List <string>;

            if (locks != null)
            {
                foreach (string s in locks)
                {
                    CoordinatedKeyManager.Unlock(s);
                }

                STEM.Sys.State.Containers.Session[details.InstructionSetID.ToString()] = null;
            }
        }
        /// <summary>
        /// This is called from Surge causing this DeploymentController to ReleaseSerializationKey
        /// </summary>
        /// <param name="details"></param>
        public override sealed void ExecutionComplete(DeploymentDetails details, List <Exception> exceptions)
        {
            try
            {
                base.ExecutionComplete(details, exceptions);
            }
            catch { }

            try
            {
                ReleaseSerializationKey(details.InitiationSource, exceptions.Count == 0);
            }
            catch { }

            SafeExecutionComplete(details, exceptions);
        }
Esempio n. 15
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            try
            {
                if (!_PreProcessResult.ContainsKey(initiationSource))
                {
                    return(null);
                }

                XmlDoc doc = _PreProcessResult[initiationSource];

                System.Collections.Generic.Dictionary <string, string> kvp = TemplateKVP.ToDictionary(i => i.Key, i => i.Value);

                lock (doc)
                {
                    if (!doc.Nodes.ContainsKey(initiationSource))
                    {
                        return(null);
                    }

                    XElement node = doc.Nodes[initiationSource];

                    foreach (XElement e in node.Descendants())
                    {
                        kvp[e.Name.LocalName] = e.Value;
                    }
                }

                InstructionSet clone = GetTemplateInstance(true);

                CustomizeInstructionSet(clone, kvp, recommendedBranchIP, initiationSource, false);

                DeploymentDetails dd = new DeploymentDetails(clone, recommendedBranchIP);

                lock (_Assignments)
                    _Assignments[dd.ISet.ID] = doc;

                return(dd);
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("XmlConsumingController.GenerateDeploymentDetails", new Exception(initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
            }

            return(null);
        }
Esempio n. 16
0
        public override void ExecutionComplete(DeploymentDetails details, List <Exception> exceptions)
        {
            base.ExecutionComplete(details, exceptions);

            XmlDoc doc = null;

            lock (_Assignments)
            {
                if (!_Assignments.ContainsKey(details.InstructionSetID))
                {
                    return;
                }

                doc = _Assignments[details.InstructionSetID];
                _Assignments.Remove(details.InstructionSetID);
            }

            if (doc != null)
            {
                lock (_Documents)
                    lock (doc)
                    {
                        if (!doc.Nodes.ContainsKey(details.InitiationSource))
                        {
                            return;
                        }

                        XElement e = doc.Nodes[details.InitiationSource];

                        doc.Nodes.Remove(details.InitiationSource);

                        if (doc.Nodes.Count == 0)
                        {
                            _Documents.Remove(doc);
                        }
                    }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// This is called from Surge
        /// </summary>
        /// <param name="key"></param>
        public override sealed void RememberDeployment(DeploymentDetails details)
        {
            //try
            //{
            //    string key = GenerateKey(details.InitiationSource);
            //    if (key == null)
            //        return;

            //    key = key.ToUpper();

            //    if (!CoordinatedKeyManager.Lock(key, this) || !CoordinatedKeyManager.Locked(key))
            //        return;

            //    lock (_Keys)
            //        _Keys[key] = new BoundKey(this, details.InitiationSource, key, true);
            //}
            //catch (Exception ex)
            //{
            //    STEM.Sys.EventLog.WriteEntry("SerialFileController.RememberDeployment", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
            //}

            SafeRememberDeployment(details);
        }
Esempio n. 18
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            DeploymentDetails ret   = null;
            List <string>     locks = new List <string>();
            Guid iSetID             = Guid.Empty;

            try
            {
                int iter = _ListMap[initiationSource];

                InstructionSet clone = GetTemplateInstance(true);

                CustomizeInstructionSet(clone, TemplateKVP, recommendedBranchIP, initiationSource, true);

                iSetID = clone.ID;

                List <List <string> > iSetLists = new List <List <string> >();
                foreach (Instruction i in clone.Instructions)
                {
                    foreach (PropertyInfo pi in i.GetType().GetProperties())
                    {
                        if (ListPropertyNames.Contains(pi.Name))
                        {
                            List <string> li = pi.GetValue(i) as List <string>;

                            if (li != null)
                            {
                                iSetLists.Add(li);
                            }
                        }
                    }
                }

                if (iSetLists.Count == 0)
                {
                    throw new Exception("No fillable properties found in InstructionSet.");
                }

                if (CoordinatedKeyManager != null)
                {
                    for (int x = (iter * GroupSize); x < ((iter * GroupSize) + GroupSize); x++)
                    {
                        if (_LastList.Count <= x)
                        {
                            break;
                        }

                        string s = ApplyKVP(_LastList[x], TemplateKVP, recommendedBranchIP, initiationSource, true);

                        if (CoordinatedKeyManager.Lock(s, CoordinateWith))
                        {
                            locks.Add(s);

                            foreach (List <string> li in iSetLists)
                            {
                                li.Add(s);
                            }
                        }
                    }
                }

                if (locks.Count == 0)
                {
                    return(null);
                }

                ret = new DeploymentDetails(clone, recommendedBranchIP);
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("GroupingController.GenerateDeploymentDetails", new Exception(InstructionSetTemplate + ": " + initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);

                foreach (string s in locks)
                {
                    CoordinatedKeyManager.Unlock(s);
                }

                locks.Clear();
            }
            finally
            {
                if (locks.Count > 0 && ret != null)
                {
                    STEM.Sys.State.Containers.Session[iSetID.ToString()] = locks;
                }
            }

            return(ret);
        }
Esempio n. 19
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            try
            {
                Dictionary <string, string> v = _QueryResults[initiationSource];

                if (v != null)
                {
                    _QueryResults.Remove(initiationSource);

                    System.Collections.Generic.Dictionary <string, string> kvp = TemplateKVP.ToDictionary(i => i.Key, i => i.Value);

                    foreach (string k in v.Keys)
                    {
                        kvp[k] = v[k];
                    }

                    InstructionSet clone = GetTemplateInstance(true);

                    CustomizeInstructionSet(clone, kvp, recommendedBranchIP, initiationSource, false);

                    DeploymentDetails dd = new DeploymentDetails(clone, recommendedBranchIP);

                    if (dd != null)
                    {
                        foreach (Instruction ins in dd.ISet.Instructions)
                        {
                            foreach (PropertyInfo prop in ins.GetType().GetProperties().Where(p => p.PropertyType.IsSubclassOf(typeof(IAuthentication))))
                            {
                                IAuthentication a = prop.GetValue(ins) as IAuthentication;

                                if (a.VersionDescriptor.TypeName == "STEM.Surge.SQLServer.Authentication")
                                {
                                    PropertyInfo i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "SqlDatabaseAddress");
                                    if (i != null)
                                    {
                                        string k = i.GetValue(a) as string;
                                        if (String.IsNullOrEmpty(k))
                                        {
                                            i.SetValue(a, Authentication.SqlDatabaseAddress);

                                            i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "SqlUser");
                                            if (i != null)
                                            {
                                                i.SetValue(a, Authentication.SqlUser);
                                            }

                                            i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "SqlPassword");
                                            if (i != null)
                                            {
                                                i.SetValue(a, Authentication.SqlPassword);
                                            }

                                            i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "SqlDatabaseName");
                                            if (i != null)
                                            {
                                                i.SetValue(a, Authentication.SqlDatabaseName);
                                            }

                                            i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "UseIntegratedSecurity");
                                            if (i != null)
                                            {
                                                i.SetValue(a, Authentication.UseIntegratedSecurity);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    return(dd);
                }
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("SQLController.GenerateDeploymentDetails", new Exception(initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
            }

            return(null);
        }
 public Entry(DeploymentDetails details)
 {
     Exceptions = 0;
     CopyFrom(details);
 }
 public virtual void SafeExecutionComplete(DeploymentDetails details, List <Exception> exceptions)
 {
 }
 public virtual void SafeRememberDeployment(DeploymentDetails details)
 {
 }
 /// <summary>
 /// This is called from Surge
 /// </summary>
 /// <param name="key"></param>
 public override sealed void RememberDeployment(DeploymentDetails details)
 {
     SafeRememberDeployment(details);
 }
Esempio n. 24
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            try
            {
                string prefix = STEM.Sys.IO.Path.GetDirectoryName(initiationSource);

                if (prefix == null)
                {
                    prefix = "";
                }
                else
                {
                    prefix = prefix.Trim(Path.DirectorySeparatorChar);

                    prefix = prefix.Substring(STEM.Sys.IO.Path.FirstTokenOfPath(initiationSource).Length);

                    prefix = prefix.Trim(Path.DirectorySeparatorChar);
                }

                TemplateKVP["[BucketName]"] = STEM.Sys.IO.Path.FirstTokenOfPath(initiationSource).ToLower();
                TemplateKVP["[KeyPrefix]"]  = prefix;

                DeploymentDetails dd = base.GenerateDeploymentDetails(listPreprocessResult, initiationSource, recommendedBranchIP, limitedToBranches);

                if (dd != null)
                {
                    foreach (Instruction ins in dd.ISet.Instructions)
                    {
                        foreach (PropertyInfo prop in ins.GetType().GetProperties().Where(p => p.PropertyType.IsSubclassOf(typeof(IAuthentication))))
                        {
                            IAuthentication a = prop.GetValue(ins) as IAuthentication;

                            if (a.VersionDescriptor.TypeName == "STEM.Surge.S3.Authentication")
                            {
                                PropertyInfo i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "AccessKey");
                                if (i != null)
                                {
                                    string k = i.GetValue(a) as string;
                                    if (String.IsNullOrEmpty(k))
                                    {
                                        i.SetValue(a, Authentication.AccessKey);

                                        i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "SecretKey");
                                        if (i != null)
                                        {
                                            i.SetValue(a, Authentication.SecretKey);
                                        }

                                        i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "Region");
                                        if (i != null)
                                        {
                                            i.SetValue(a, Authentication.Region);
                                        }

                                        i = a.GetType().GetProperties().FirstOrDefault(p => p.Name == "ServiceURL");
                                        if (i != null)
                                        {
                                            i.SetValue(a, Authentication.ServiceURL);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(dd);
            }
            finally
            {
                TemplateKVP["[BucketName]"] = "Reserved";
                TemplateKVP["[KeyPrefix]"]  = "Reserved";
            }
        }
Esempio n. 25
0
        public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches)
        {
            try
            {
                Dictionary <string, long> col;

                lock (_KnownSizes)
                {
                    if (!_KnownSizes.ContainsKey(DeploymentControllerID))
                    {
                        _KnownSizes[DeploymentControllerID] = new Dictionary <string, long>();
                    }

                    col = _KnownSizes[DeploymentControllerID];
                }

                long sz = 0;
                lock (col)
                    sz = col[initiationSource];

                if (!_Ranges.ContainsKey(DeploymentControllerID))
                {
                    lock (_Ranges)
                        if (!_Ranges.ContainsKey(DeploymentControllerID))
                        {
                            _Ranges[DeploymentControllerID] = new List <SizeRange>();
                        }
                }

                SizeRange range = null;
                lock (_Ranges[DeploymentControllerID])
                    range = _Ranges[DeploymentControllerID].FirstOrDefault(i => i.MinMB <= sz && i.MaxMB >= sz);

                if (range == null)
                {
                    return(null);
                }

                lock (range)
                {
                    SizeRange.Load load = range.ActiveLoads.Where(i => i.IP == recommendedBranchIP).FirstOrDefault();

                    if (load != null && load.Loaded.Count < range.MaxLoadPerBranch)
                    {
                        DeploymentDetails ret = base.GenerateDeploymentDetails(listPreprocessResult, initiationSource, load.IP, limitedToBranches);

                        if (ret != null)
                        {
                            load.Loaded.Add(initiationSource);
                            load.LastAssignment = DateTime.UtcNow;
                        }

                        return(ret);
                    }
                }
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("FileSizeSubsetController.GenerateDeploymentDetails", new Exception(InstructionSetTemplate + ": " + initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
            }

            return(null);
        }