Esempio n. 1
0
        private void OnUpdateInstance(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnUpdateInstanceRequestDebugLogMessage, ServiceDescription(), msg, reply);

            object[] request = new object[0];
            request = JsonConvertibleObject.DeserializeFromJsonArray(msg);

            Handle provisionCredentialsHandle = new Handle();
            provisionCredentialsHandle.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(request[0].ToString()));

            ServiceCredentials provisionCredentials = provisionCredentialsHandle.Credentials;
            Dictionary<string, object> bindingCredentialsHash = new Dictionary<string, object>();

            object[] bindingCredentialsHandle = new object[0];
            bindingCredentialsHandle = JsonConvertibleObject.DeserializeFromJsonArray(request[1].ToString());

            foreach (object obj in bindingCredentialsHandle)
            {
                Handle handle = new Handle();
                handle.FromJsonIntermediateObject(obj);
                bindingCredentialsHash.Add(handle.ServiceId, handle.Credentials);
            }

            Collection<object> responseHandles = new Collection<object>();
            provisionCredentials.ServiceWorkFactory.StartNew(
                () =>
                {
                    try
                    {
                        object[] result = this.UpdateInstance(provisionCredentialsHandle.Credentials, bindingCredentialsHash);
                        capacity -= CapacityUnit();

                        provisionCredentials = (ServiceCredentials)result[0];
                        bindingCredentialsHash = (Dictionary<string, object>)result[1];
                        provisionCredentials.NodeId = this.nodeId;
                        provisionCredentialsHandle.Credentials = provisionCredentials;

                        responseHandles.Add(provisionCredentialsHandle.ToJson());

                        foreach (object obj in bindingCredentialsHandle)
                        {
                            Handle handle = new Handle();
                            handle.FromJsonIntermediateObject(obj);
                            handle.Credentials = (ServiceCredentials)bindingCredentialsHash[handle.ServiceId];
                            responseHandles.Add(handle.ToJson());
                        }

                        object[] response = responseHandles.ToArray();
                        nodeNats.Publish(reply, null, JsonConvertibleObject.SerializeToJson(response));
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning(ex.ToString());
                        SimpleResponse response = new SimpleResponse();
                        nodeNats.Publish(reply, null, EncodeFailure(response, ex));
                    }
                });
        }
Esempio n. 2
0
        private void OnImportInstance(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnImportInstanceDebugLogMessage, ServiceDescription(), msg, reply);
            object[] request = new object[0];
            request = JsonConvertibleObject.DeserializeFromJsonArray(msg);

            Handle provisionCredentialsHandle = new Handle();
            provisionCredentialsHandle.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(request[0].ToString()));

            ServiceCredentials provisionCredentials = provisionCredentialsHandle.Credentials;
            Dictionary<string, object> bindingCredentialsHash = new Dictionary<string, object>();

            object[] bindingCredentialsHandle = new object[0];
            bindingCredentialsHandle = JsonConvertibleObject.DeserializeFromJsonArray(request[1].ToString());

            foreach (object obj in bindingCredentialsHandle)
            {
                Handle handle = new Handle();
                handle.FromJsonIntermediateObject(obj);
                bindingCredentialsHash.Add(handle.ServiceId, handle.Credentials);
            }

            string plan = provisionCredentialsHandle.Configuration.Plan;

            provisionCredentials.ServiceWorkFactory.StartNew(
                () =>
                {
                    SimpleResponse response = new SimpleResponse();

                    try
                    {
                        string instance = provisionCredentials.Name;
                        string file_path = this.GetMigrationFolder(instance);

                        bool result = this.ImportInstance(provisionCredentials, bindingCredentialsHash, file_path, plan);
                        if (result)
                        {
                            nodeNats.Publish(reply, null, EncodeSuccess(response));
                        }
                        else
                        {
                            nodeNats.Publish(reply, null, EncodeFailure(response));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning(ex.ToString());
                        nodeNats.Publish(reply, null, EncodeFailure(response));
                    }
                });
        }
Esempio n. 3
0
        private void OnCleanupNfs(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.CleanupNfsLogMessage, ServiceDescription(), msg, reply);
            object[] request = new object[0];
            request = JsonConvertibleObject.DeserializeFromJsonArray(msg);

            Handle prov_cred = new Handle();
            prov_cred.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(request[0].ToString()));

            prov_cred.Credentials.ServiceWorkFactory.StartNew(
                () =>
                {
                    SimpleResponse response = new SimpleResponse();

                    try
                    {
                        string instance = prov_cred.ServiceId;
                        Directory.Delete(this.GetMigrationFolder(instance), true);

                        nodeNats.Publish(reply, null, EncodeSuccess(response));
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning(ex.ToString());
                        nodeNats.Publish(reply, null, EncodeFailure(response, ex));
                    }
                });
        }
Esempio n. 4
0
        private void OnEnableInstance(string msg, string reply, string subject)
        {
            Logger.Debug(Strings.OnEnableInstanceDebugMessage, ServiceDescription(), msg, reply);
            object[] request = new object[0];
            request = JsonConvertibleObject.DeserializeFromJsonArray(msg);

            Handle provisionCredentialsHandle = new Handle();
            provisionCredentialsHandle.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(request[0].ToString()));

            ServiceCredentials provisionCredentials = provisionCredentialsHandle.Credentials;
            Dictionary<string, object> bindingCredentialsHash = new Dictionary<string, object>();

            Handle[] bindingCredentialsHandle = new Handle[0];
            bindingCredentialsHandle = JsonConvertibleObject.ObjectToValue<Handle[]>(request[1]);
            foreach (Handle handle in bindingCredentialsHandle)
            {
                bindingCredentialsHash.Add(handle.ServiceId, handle.Credentials);
            }

            provisionCredentials.ServiceWorkFactory.StartNew(
                () =>
                {
                    SimpleResponse response = new SimpleResponse();
                    try
                    {
                        bool result = this.EnableInstance(ref provisionCredentials, ref bindingCredentialsHash);

                        if (result)
                        {
                            nodeNats.Publish(reply, null, EncodeSuccess(response));
                        }
                        else
                        {
                            nodeNats.Publish(reply, null, EncodeFailure(response));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning(ex.ToString());
                    }
                });
        }
Esempio n. 5
0
        /// <summary>
        /// Checks the specified service handles to see if they're orphaned.
        /// </summary>
        /// <param name="handles">The service handles (service ids and credentials).</param>
        private void CheckOrphan(Handle[] handles)
        {
            if (handles == null)
            {
                throw new ServiceException(ServiceException.NotFound, "No handles for checking orphan");
            }

            string[] live_ins_list = this.AllInstancesList();

            Dictionary<string, object> orphanInstancesHash = new Dictionary<string, object>();

            List<string> orphanInstancesList = new List<string>();

            foreach (string name in live_ins_list)
            {
                if (!handles.Any(h => h.Credentials.NodeId == this.nodeId && h.ServiceId == name))
                {
                    orphanInstancesList.Add(name);
                }
            }

            ServiceCredentials[] liveBindList = this.AllBindingsList();
            Dictionary<string, object> orphanBindingHash = new Dictionary<string, object>();

            List<ServiceCredentials> orphanBindingsList = new List<ServiceCredentials>();

            foreach (ServiceCredentials credential in liveBindList)
            {
                if (!handles.Any(h => h.Credentials.Name == credential.Name && h.Credentials.UserName == credential.UserName))
                {
                    orphanBindingsList.Add(credential);
                }
            }

            Logger.Debug(Strings.CheckOrphanDebugLogMessage, orphanInstancesList.Count, orphanBindingsList.Count);
            orphanInstancesHash[this.nodeId.ToString()] = orphanInstancesList;
            orphanBindingHash[this.nodeId.ToString()] = orphanBindingsList;
            this.orphanInstancesHash = orphanInstancesHash;
            this.orphanBindingHash = orphanBindingHash;
        }