示例#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));
                    }
                });
        }
示例#2
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());
                    }
                });
        }
示例#3
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));
                    }
                });
        }
示例#4
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));
                    }
                });
        }