Esempio n. 1
0
        public static LogsetStatus GetStatus(LogsharkRequest request)
        {
            LogsetMetadata logsetMetadata;
            LogsetType     logsetType;

            try
            {
                LogsetMetadataReader metadataReader = new LogsetMetadataReader(request);

                if (!RemoteLogsetHasData(request))
                {
                    return(LogsetStatus.NonExistent);
                }

                logsetMetadata = metadataReader.GetMetadata();
                logsetType     = metadataReader.GetLogsetType();
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Unable to retrieve logset metadata from MongoDB: {0}", ex.Message);
                return(LogsetStatus.Indeterminable);
            }

            // Lack of metadata is treated as a corrupt state.
            if (logsetMetadata == null || logsetMetadata.CollectionsParsed == null || logsetType == LogsetType.Unknown)
            {
                return(LogsetStatus.Corrupt);
            }

            if (!logsetMetadata.ProcessedSuccessfully)
            {
                if (logsetMetadata.IsHeartbeatExpired())
                {
                    return(LogsetStatus.Corrupt);
                }
                else
                {
                    return(LogsetStatus.InFlight);
                }
            }

            // Check to make sure the remote logset has all of the collections we need.
            var missingCollections = LogsetDependencyHelper.GetMissingRequiredCollections(request, logsetType, logsetMetadata.CollectionsParsed);

            if (missingCollections.Count > 0)
            {
                Log.DebugFormat("Remote {0} logset does not contain required collections: {1}", logsetType, String.Join(", ", missingCollections));
                return(LogsetStatus.Incomplete);
            }

            return(LogsetStatus.Valid);
        }
Esempio n. 2
0
        /// <summary>
        /// Takes action to process a logset based on the current status of the Logset.
        /// </summary>
        protected void ProcessLogset(LogsharkRequest request, IArtifactProcessor artifactProcessor)
        {
            LogsetStatus existingProcessedLogsetStatus = LogsharkController.GetExistingLogsetStatus(request);

            if (request.ForceParse && !request.Target.IsHashId)
            {
                // If we are forcing a reparsing of this logset, first drop any existing logset in our MongoCluster which matches this hash-id.
                if (existingProcessedLogsetStatus != LogsetStatus.NonExistent)
                {
                    Log.InfoFormat("'Force Parse' request issued, dropping existing Mongo database '{0}'..", request.RunContext.MongoDatabaseName);
                    MongoAdminUtil.DropDatabase(request.Configuration.MongoConnectionInfo.GetClient(), request.RunContext.MongoDatabaseName);
                }

                ParseLogset(request, artifactProcessor);
                return;
            }

            switch (existingProcessedLogsetStatus)
            {
            case LogsetStatus.NonExistent:
                if (request.Target.IsHashId)
                {
                    request.RunContext.IsValidLogset = false;
                    throw new InvalidTargetHashException(String.Format("No logset exists that matches logset hash '{0}'. Aborting..", request.RunContext.LogsetHash));
                }
                ParseLogset(request, artifactProcessor);
                break;

            case LogsetStatus.Corrupt:
                if (request.Target.IsHashId)
                {
                    request.RunContext.IsValidLogset = false;
                    throw new InvalidTargetHashException(String.Format("Mongo database matching logset hash '{0}' exists but is corrupted. Aborting..", request.RunContext.LogsetHash));
                }
                Log.InfoFormat("Logset matching hash '{0}' exists but is corrupted. Dropping it and reprocessing..", request.RunContext.MongoDatabaseName);
                MongoAdminUtil.DropDatabase(request.Configuration.MongoConnectionInfo.GetClient(), request.RunContext.MongoDatabaseName);
                ParseLogset(request, artifactProcessor);
                break;

            case LogsetStatus.InFlight:
                string collisionErrorMessage = String.Format("Logset matching hash '{0}' exists but is currently being processed by another user.  Aborting..", request.RunContext.MongoDatabaseName);
                Log.InfoFormat(collisionErrorMessage);
                throw new ProcessingUserCollisionException(collisionErrorMessage);

            case LogsetStatus.Incomplete:
                if (request.Target.IsHashId)
                {
                    throw new InvalidTargetHashException("Found existing logset matching hash, but it is a partial logset that does not contain all of the data required to run specified plugins. Aborting..");
                }
                MongoAdminUtil.DropDatabase(request.Configuration.MongoConnectionInfo.GetClient(), request.RunContext.MongoDatabaseName);
                Log.Info("Found existing logset matching hash, but it is a partial logset that does not contain all of the data required to run specified plugins. Dropping it and reprocessing..");
                ParseLogset(request, artifactProcessor);
                break;

            case LogsetStatus.Indeterminable:
                throw new IndeterminableLogsetStatusException("Unable to determine status of logset. Aborting..");

            case LogsetStatus.Valid:
                request.RunContext.UtilizedExistingProcessedLogset = true;
                request.RunContext.IsValidLogset = true;
                Log.Info("Found existing logset matching hash, skipping extraction and parsing.");
                LogsetMetadataReader.SetLogsetType(request);
                LogsetMetadataReader.SetLogsetSize(request);
                break;

            default:
                throw new ArgumentOutOfRangeException(String.Format("'{0}' is not a valid LogsetStatus!", existingProcessedLogsetStatus));
            }

            LogsharkController.ValidateMongoDatabaseContainsData(request);
        }