Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
Merged
3 changes: 3 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ endif

SRCS=\
metadatad.cc \
agent.cc \
api_server.cc \
store.cc \
reporter.cc \
configuration.cc \
updater.cc \
instance.cc \
Expand Down
38 changes: 38 additions & 0 deletions src/agent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2018 Google Inc.
*
* Licensed 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.
**/

#include "agent.h"

#include "configuration.h"
#include "api_server.h"
#include "reporter.h"

namespace google {

MetadataAgent::MetadataAgent(const MetadataAgentConfiguration& config)
: config_(config), store_(config_) {}

MetadataAgent::~MetadataAgent() {}

void MetadataAgent::start() {
metadata_api_server_.reset(new MetadataApiServer(
config_, store_, config_.MetadataApiNumThreads(), "0.0.0.0",
config_.MetadataApiPort()));
reporter_.reset(new MetadataReporter(
config_, &store_, config_.MetadataReporterIntervalSeconds()));
}

}
71 changes: 71 additions & 0 deletions src/agent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2018 Google Inc.
*
* Licensed 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.
**/
#ifndef AGENT_H_
#define AGENT_H_

//#include "config.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove unnecessary imports, same throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific one was a "reminder" to set up autotools to make this more portable. It appears all over the place. Probably no sense in keeping it, but I'd rather do it as a separate cleanup to keep this PR focused.


#include <memory>

#include "store.h"

namespace google {

// Configuration object.
class MetadataAgentConfiguration;

// A server that implements the metadata agent API.
class MetadataApiServer;

// A periodic reporter of metadata to Stackdriver.
class MetadataReporter;

// Runs the metadata tasks.
class MetadataAgent {
public:
MetadataAgent(const MetadataAgentConfiguration& config);
~MetadataAgent();

// Starts serving.
void start();

const MetadataAgentConfiguration& config() const {
return config_;
}

const MetadataStore& store() const {
return store_;
}

MetadataStore* mutable_store() {
return &store_;
}

private:
const MetadataAgentConfiguration& config_;

// The store for the metadata.
MetadataStore store_;

// The Metadata API server.
std::unique_ptr<MetadataApiServer> metadata_api_server_;
// The metadata reporter.
std::unique_ptr<MetadataReporter> reporter_;
};

}

#endif // AGENT_H_
Loading