0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
OperationStop.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include <Common/Compat.h>
23 
24 #include "OperationStop.h"
25 
27 
28 #include <Common/Error.h>
29 #include <Common/FailureInducer.h>
30 #include <Common/ScopeGuard.h>
31 #include <Common/Serialization.h>
32 #include <Common/StringExt.h>
33 #include <Common/System.h>
34 #include <Common/md5.h>
35 
36 using namespace Hypertable;
37 
39  : OperationEphemeral(context, event, MetaLog::EntityType::OPERATION_STOP) {
40  const uint8_t *ptr = event->payload;
41  size_t remaining = event->payload_len;
42  m_params.decode(&ptr, &remaining);
44 }
45 
47  HT_INFOF("Entering OperationStop-%s state=%s",
48  m_params.server().c_str(), OperationState::get_text(m_state));
49 
50  try {
52  CommAddress addr;
53 
54  addr.set_proxy(m_params.server());
55  rsc.shutdown(addr);
56  }
57  catch (Exception &e) {
61  else
63  return;
64  }
65 
66  complete_ok();
67 
68  HT_INFOF("Leaving OperationStop-%s state=%s",
69  m_params.server().c_str(), OperationState::get_text(m_state));
70 }
71 
72 void OperationStop::display_state(std::ostream &os) {
73  os << " " << m_params.server() << " ";
74 }
75 
77  return "OperationStop";
78 }
79 
81  return format("OperationStop %s", m_params.server().c_str());
82 }
Retrieves system information (hardware, installation directory, etc)
The FailureInducer simulates errors.
ContextPtr m_context
Pointer to Master context.
Definition: Operation.h:553
Abstract base class for ephemeral operations.
void display_state(std::ostream &os) override
Write human readable operation state to output stream.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
Declarations for RangeServerClient.
const char * get_text(int32_t state)
Definition: Operation.cc:609
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
const char * INIT
Definition: Operation.cc:45
void set_proxy(const String &str)
Sets address type to CommAddress::PROXY and proxy name to p.
Definition: CommAddress.h:76
void shutdown(const CommAddress &addr)
Issues a "shutdown" request.
Definition: Client.cc:545
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
Hypertable definitions
const String name() override
Name of operation used for exclusivity.
void execute() override
Executes (carries out) the operation.
OperationStop(ContextPtr &context, EventPtr &event)
DependencySet m_dependencies
Set of dependencies.
Definition: Operation.h:595
#define HT_INFOF(msg,...)
Definition: Logger.h:272
Lib::Master::Request::Parameters::Stop m_params
Request parmaeters.
Definition: OperationStop.h:44
Client interface to RangeServer.
Definition: Client.h:63
This is a generic exception class for Hypertable.
Definition: Error.h:314
void complete_ok(std::vector< MetaLog::EntityPtr > &additional)
Definition: Operation.cc:436
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
void complete_error(int error, const String &msg, std::vector< MetaLog::EntityPtr > &additional)
Completes operation with error.
Definition: Operation.cc:400
md5 digest routines.
const String label() override
Human readable label for operation.
Address abstraction to hold either proxy name or IPv4:port address.
Definition: CommAddress.h:52
const string & server() const
Gets name of RangeServer to be stopped.
Definition: Stop.h:61
int code() const
Returns the error code.
Definition: Error.h:391
Executes user-defined functions when leaving the current scope.