Example #1
0
        private static string ExtractRequestParam(IReplicationRequest request, string paramName)
        {
            string param = request.QueryParam(paramName);

            if (param == null)
            {
                throw new InvalidOperationException("Missing mandatory parameter: " + paramName);
            }
            return(param);
        }
Example #2
0
        private static string ExtractRequestParam(IReplicationRequest request, string paramName)
        {
            string param = request.QueryParam(paramName);

            if (param == null)
            {
                throw IllegalStateException.Create("Missing mandatory parameter: " + paramName);
            }
            return(param);
        }
Example #3
0
        /// <summary>
        /// Returns the path elements that were given in the servlet request, excluding the servlet's action context.
        /// </summary>
        private string[] GetPathElements(IReplicationRequest request)
        {
            string path = request.Path;

            int actionLength = context.Length;
            int startIndex   = actionLength;

            if (path.Length > actionLength && path[actionLength] == '/')
            {
                ++startIndex;
            }

            return(path.Substring(startIndex).Split('/').TrimEnd());
        }
Example #4
0
 internal static void HandleSubscriberRequest(IReplicationRequest req)
 {
     try
     {
         Type msgType = req.GetType();
         if (typeof(IReplicationRequest).IsAssignableFrom(msgType))
         {
             if (typeof(ReplicationSessionAmAlive) == msgType)
             {
                 ReplicationSessionAmAlive alive = (ReplicationSessionAmAlive)req;
                 GetDetails(alive.ClientKey).LastHeartBeatResponse = DateTime.Now;
                 //SystemLogger.WriteOnConsole(true, string.Format("Client {0} is alive @ {1} el7amdolelah!", alive.ClientKey, DateTime.Now), ConsoleColor.Gray, ConsoleColor.Black, false);
             }
         }
     }
     catch (Exception ex)
     {
         Counters.IncrementCounter(CountersConstants.ExceptionMessages);
         SystemLogger.WriteOnConsoleAsync(true, string.Format("Error setting client LastHeartBeatResponse, Error: {0} ", ex.Message), ConsoleColor.Cyan, ConsoleColor.Black, true);
     }
 }
Example #5
0
        // LUCENENET specific - copy method not used

        /// <summary>
        /// Executes the replication task.
        /// </summary>
        /// <exception cref="InvalidOperationException">required parameters are missing</exception>
        public virtual void Perform(IReplicationRequest request, IReplicationResponse response)
        {
            string[] pathElements = GetPathElements(request);
            if (pathElements.Length != 2)
            {
                throw new InvalidOperationException("invalid path, must contain shard ID and action, e.g. */s1/update");
            }

            if (!Enum.TryParse(pathElements[ACTION_IDX], true, out ReplicationAction action))
            {
                throw new InvalidOperationException("Unsupported action provided: " + pathElements[ACTION_IDX]);
            }

            if (!replicators.TryGetValue(pathElements[SHARD_IDX], out IReplicator replicator))
            {
                throw new InvalidOperationException("unrecognized shard ID " + pathElements[SHARD_IDX]);
            }

            // SOLR-8933 Don't close this stream.
            try
            {
                switch (action)
                {
                case ReplicationAction.OBTAIN:
                    string sessionId = ExtractRequestParam(request, REPLICATE_SESSION_ID_PARAM);
                    string fileName  = ExtractRequestParam(request, REPLICATE_FILENAME_PARAM);
                    string source    = ExtractRequestParam(request, REPLICATE_SOURCE_PARAM);
                    using (Stream stream = replicator.ObtainFile(sessionId, source, fileName))
                        stream.CopyTo(response.Body);
                    break;

                case ReplicationAction.RELEASE:
                    replicator.Release(ExtractRequestParam(request, REPLICATE_SESSION_ID_PARAM));
                    break;

                case ReplicationAction.UPDATE:
                    string       currentVersion = request.QueryParam(REPLICATE_VERSION_PARAM);
                    SessionToken token          = replicator.CheckForUpdate(currentVersion);
                    if (token == null)
                    {
                        response.Body.Write(new byte[] { 0 }, 0, 1);     // marker for null token
                    }
                    else
                    {
                        response.Body.Write(new byte[] { 1 }, 0, 1);
                        token.Serialize(new DataOutputStream(response.Body));
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                response.StatusCode = 500;
                try
                {
                    TextWriter     writer     = new StreamWriter(response.Body);
                    JsonSerializer serializer = JsonSerializer.Create(JSON_SERIALIZER_SETTINGS);
                    serializer.Serialize(writer, e, e.GetType());
                }
                catch (Exception exception)
                {
                    throw new IOException("Could not serialize", exception);
                }
            }
            finally
            {
                response.Flush();
            }
        }