blob: eb88cf077c5f6cbcd4606ee1ab10b7c5b9d8b0cf [file] [log] [blame]
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
using System;
using Org.Apache.REEF.Common.Context;
using Org.Apache.REEF.Common.Services;
using Org.Apache.REEF.Common.Tasks;
using Org.Apache.REEF.Common.Telemetry;
using Org.Apache.REEF.Driver;
using Org.Apache.REEF.Driver.Context;
using Org.Apache.REEF.Driver.Evaluator;
using Org.Apache.REEF.Tang.Annotations;
using Org.Apache.REEF.Tang.Implementations.Configuration;
using Org.Apache.REEF.Tang.Util;
using Org.Apache.REEF.Tests.Functional.Messaging;
using Org.Apache.REEF.Utilities.Logging;
namespace Org.Apache.REEF.Tests.Functional.Telemetry
{
class MetricsDriver :
IObserver<IDriverStarted>,
IObserver<IAllocatedEvaluator>,
IObserver<IActiveContext>
{
private static readonly Logger Logger = Logger.GetLogger(typeof(MessageDriver));
private readonly IEvaluatorRequestor _evaluatorRequestor;
[Inject]
public MetricsDriver(IEvaluatorRequestor evaluatorRequestor)
{
_evaluatorRequestor = evaluatorRequestor;
}
public void OnNext(IDriverStarted value)
{
var request =
_evaluatorRequestor.NewBuilder()
.SetNumber(1)
.SetMegabytes(512)
.SetCores(2)
.SetRackName("WonderlandRack")
.SetEvaluatorBatchId("MetricsEvaluator")
.Build();
_evaluatorRequestor.Submit(request);
}
public void OnNext(IAllocatedEvaluator value)
{
Logger.Log(Level.Info, "Received IAllocatedEvaluator");
const string contextId = "ContextID";
var serviceConfiguration = ServiceConfiguration.ConfigurationModule
.Build();
var contextConfiguration1 = ContextConfiguration.ConfigurationModule
.Set(ContextConfiguration.Identifier, contextId)
////.Set(ContextConfiguration.OnSendMessage, GenericType<MetricsMessageSender>.Class)
.Build();
var contextConfiguration2 = MessageSenderConfigurationModule.ConfigurationModule.Build();
var contextConfiguration = Configurations.Merge(contextConfiguration1, contextConfiguration2);
value.SubmitContextAndService(contextConfiguration, serviceConfiguration);
}
public void OnNext(IActiveContext activeContext)
{
Logger.Log(Level.Info, "Received IActiveContext");
const string taskId = "TaskID";
var taskConfiguration = TaskConfiguration.ConfigurationModule
.Set(TaskConfiguration.Identifier, taskId)
.Set(TaskConfiguration.Task, GenericType<MetricsTask>.Class)
.Build();
activeContext.SubmitTask(taskConfiguration);
}
public void OnCompleted()
{
throw new NotImplementedException();
}
public void OnError(Exception error)
{
throw new NotImplementedException();
}
}
}