IceStopper.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Nicola Miskowiec
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #include "IceStatusReader.h"
27 #include "IceStopper.h"
28 
30 
31 using namespace ScenarioManager;
32 using namespace Exec;
33 using namespace Data_Structure;
34 using namespace Generator;
35 
36 IceStopper::IceStopper(const IceGrid::AdminPrx admin) : admin(admin)
37 {
38 
39 }
40 
42 {
43  try
44  {
45  auto appId = IceStatusReader::GetApplicationId(application);
46  ARMARX_VERBOSE << "Disabling " << appId;
47  admin->enableServer(appId, false);
48  ARMARX_VERBOSE << "Stopping " << appId;
49  admin->stopServer(appId);
50  }
51  catch (IceGrid::ServerNotExistException& ex)
52  {
53  ARMARX_ERROR_S << "Unable to stop Application " << application->getName() << " because it is not existent";
54  }
55  catch (IceGrid::ServerStopException& ex)
56  {
57  ARMARX_ERROR_S << "Unable to stop Application " << application->getName() << " because the server does not react";
58  }
59  catch (IceGrid::NodeUnreachableException& ex)
60  {
61  ARMARX_ERROR_S << "Unable to stop Application " << application->getName() << " because the Server node is unreachable";
62  }
63  catch (IceGrid::DeploymentException& ex)
64  {
65  ARMARX_ERROR_S << "Unable to stop Application " << application->getName() << " because it is not deployed";
66  }
67 }
68 
70 {
71  try
72  {
73  auto appId = IceStatusReader::GetApplicationId(application);
74  ARMARX_VERBOSE << "Disabling " << appId;
75  admin->enableServer(appId, false);
76  ARMARX_VERBOSE << "Killing " << appId;
77  admin->sendSignal(appId, "9");
78  }
79  catch (IceGrid::ServerNotExistException& ex)
80  {
81  ARMARX_ERROR_S << "Unable to kill Application " << application->getName() << " because it is not existent";
82  }
83  catch (IceGrid::BadSignalException& ex)
84  {
85  ARMARX_ERROR_S << "Unable to kill Application " << application->getName() << " because the signal is not recognized by the Server";
86  }
87  catch (IceGrid::NodeUnreachableException& ex)
88  {
89  ARMARX_ERROR_S << "Unable to kill Application " << application->getName() << " because the Server node is unreachable";
90  }
91  catch (IceGrid::DeploymentException& ex)
92  {
93  ARMARX_ERROR_S << "Unable to kill Application " << application->getName() << " because it is not deployed";
94  }
95 }
96 
98 {
99  std::vector<std::string> appNames = admin->getAllApplicationNames();
100 
101  if (std::find(appNames.begin(), appNames.end(), application->getScenario()->getName()) != appNames.end())
102  {
103  try
104  {
105  IceGridXmlGenerator generator;
106  IceGrid::ApplicationDescriptor descriptor = admin->getApplicationInfo(application->getScenario()->getName()).descriptor;
107  IceGrid::ApplicationUpdateDescriptor appUpdate = generator.generateUpdateDescriptor(descriptor);
108  auto location = std::find_if(appUpdate.nodes.begin(), appUpdate.nodes.end(), [application](const IceGrid::NodeUpdateDescriptor & d)
109  {
110  return d.name == application->getEffectiveNodeName();
111  });
112  if (location == appUpdate.nodes.end())
113  {
114  ARMARX_ERROR_S << "Error while removing an Application in an not exitend node";
115  return;
116  }
117  //If there is only this server left remove the whole application
118  if ((*location).serverInstances.size() == 1)
119  {
120  removeScenario(application->getScenario(), statusManager);
121  }
122  else
123  {
124  (*location).removeServers.push_back(IceStatusReader::GetApplicationId(application));
125  auto loc = std::find_if((*location).serverInstances.begin(), (*location).serverInstances.end(), [application](const IceGrid::ServerInstanceDescriptor & d)
126  {
127  return d.parameterValues.at("component") == application->getName()
128  && d.parameterValues.at("componentId") == application->getInstanceName();
129  });
130  if (loc != (*location).serverInstances.end())
131  {
132  (*location).serverInstances.erase(loc);
133  }
134  ARMARX_INFO << "Removing application " << application->getName();
135  admin->updateApplication(appUpdate);
136  ARMARX_INFO << "Removed application " << application->getName();
137  }
138  }
139  catch (IceGrid::AccessDeniedException& ex)
140  {
141  ARMARX_ERROR_S << "Error while removing Application " << application->getName() << " another application has the accesss rights to the IceGridAdmin. (Please try again)";
142  }
143  catch (IceGrid::ApplicationNotExistException& ex)
144  {
145  ARMARX_ERROR_S << "ScenarioManager error: this should not happen";
146  }
147  }
148 }
149 
151 {
152  std::vector<std::string> appNames = admin->getAllApplicationNames();
153  if (std::find(appNames.begin(), appNames.end(), scenario->getName()) != appNames.end())
154  {
155  try
156  {
157  ARMARX_INFO << "Removing scenario " << scenario->getName();
158  admin->removeApplication(scenario->getName());
159  ARMARX_INFO << "Removed scenario " << scenario->getName();
160  //statusManager.setIceScenario(scenario, false);
161  }
162  catch (IceGrid::AccessDeniedException& ex)
163  {
164  ARMARX_ERROR_S << "Error while deploying Scenario " << scenario->getName() << " another application has the accesss rights to the IceGridAdmin. (Please try again)";
165  }
166  catch (IceGrid::DeploymentException& ex)
167  {
168  ARMARX_ERROR_S << "Error while deploying Scenario" << scenario->getName();
169  }
170  catch (IceGrid::ApplicationNotExistException& ex)
171  {
172  ARMARX_ERROR_S << "ScenarioManager error: this should not happen";
173  }
174  }
175 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
IceStatusReader.h
ScenarioManager::Data_Structure::ApplicationInstancePtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
Definition: ApplicationInstance.h:33
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
IceStopper.h
ScenarioManager::Exec::IceStopper::kill
void kill(Data_Structure::ApplicationInstancePtr application) override
Kills an application.
Definition: IceStopper.cpp:69
ScenarioManager::Exec::IceStopper::IceStopper
IceStopper(const IceGrid::AdminPrx admin)
Definition: IceStopper.cpp:36
ApplicationInstancePtr
std::shared_ptr< ScenarioManager::Data_Structure::ApplicationInstance > ApplicationInstancePtr
Definition: StopStrategy.h:7
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
ScenarioManager::Exec::IceStopper::removeScenario
virtual void removeScenario(Data_Structure::ScenarioPtr scenario, StatusManager statusManager) override
Definition: IceStopper.cpp:150
ScenarioManager::StatusManager
Definition: StatusManager.h:7
IceGridXmlGenerator.h
ScenarioManager::Exec::IceStopper::removeApplication
virtual void removeApplication(Data_Structure::ApplicationInstancePtr application, StatusManager statusManager) override
Definition: IceStopper.cpp:97
ScenarioManager
Definition: Application.cpp:166
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
ScenarioManager::Exec::IceStopper::stop
void stop(Data_Structure::ApplicationInstancePtr application) override
Stops an application.
Definition: IceStopper.cpp:41
ScenarioManager::Exec::IceStatusReader::GetApplicationId
static std::string GetApplicationId(const ApplicationInstancePtr &application)
Definition: IceStatusReader.cpp:89