1
# Copyright (c) 2014 Mirantis Inc.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
16
from sahara.i18n import _
17
from sahara.i18n import _LE
18
from sahara.openstack.common import log as logging
19
from sahara.plugins.cdh import cloudera_utils as cmu
20
from sahara.plugins.cdh import utils as cu
21
from sahara.plugins.general import exceptions as ex
22
from sahara.plugins.general import utils as u
23
from sahara.utils import general as gu
25
LOG = logging.getLogger(__name__)
28
def validate_cluster_creating(cluster):
29
if not cmu.have_cm_api_libs():
30
LOG.error(_LE("For provisioning cluster with CDH plugin install"
31
"'cm_api' package version 6.0.2 or later."))
32
raise ex.HadoopProvisionError(_("'cm_api' is not installed."))
34
mng_count = _get_inst_count(cluster, 'MANAGER')
36
raise ex.InvalidComponentCountException('MANAGER', 1, mng_count)
38
nn_count = _get_inst_count(cluster, 'NAMENODE')
40
raise ex.InvalidComponentCountException('NAMENODE', 1, nn_count)
42
snn_count = _get_inst_count(cluster, 'SECONDARYNAMENODE')
44
raise ex.InvalidComponentCountException('SECONDARYNAMENODE', 1,
47
rm_count = _get_inst_count(cluster, 'RESOURCEMANAGER')
48
if rm_count not in [0, 1]:
49
raise ex.InvalidComponentCountException('RESOURCEMANAGER', '0 or 1',
52
hs_count = _get_inst_count(cluster, 'JOBHISTORY')
53
if hs_count not in [0, 1]:
54
raise ex.InvalidComponentCountException('JOBHISTORY', '0 or 1',
57
if rm_count > 0 and hs_count < 1:
58
raise ex.RequiredServiceMissingException('JOBHISTORY',
59
required_by='RESOURCEMANAGER')
61
nm_count = _get_inst_count(cluster, 'NODEMANAGER')
64
raise ex.RequiredServiceMissingException('RESOURCEMANAGER',
65
required_by='NODEMANAGER')
67
oo_count = _get_inst_count(cluster, 'OOZIE_SERVER')
68
dn_count = _get_inst_count(cluster, 'DATANODE')
69
if oo_count not in [0, 1]:
70
raise ex.InvalidComponentCountException('OOZIE_SERVER', '0 or 1',
75
raise ex.RequiredServiceMissingException(
76
'DATANODE', required_by='OOZIE_SERVER')
79
raise ex.RequiredServiceMissingException(
80
'NODEMANAGER', required_by='OOZIE_SERVER')
83
raise ex.RequiredServiceMissingException(
84
'JOBHISTORY', required_by='OOZIE_SERVER')
87
def validate_additional_ng_scaling(cluster, additional):
88
rm = cu.get_resourcemanager(cluster)
89
scalable_processes = _get_scalable_processes()
91
for ng_id in additional:
92
ng = gu.get_by_id(cluster.node_groups, ng_id)
93
if not set(ng.node_processes).issubset(scalable_processes):
94
msg = _("CDH plugin cannot scale nodegroup with processes: "
96
raise ex.NodeGroupCannotBeScaled(
97
ng.name, msg % {'processes': ' '.join(ng.node_processes)})
99
if not rm and 'NODEMANAGER' in ng.node_processes:
100
msg = _("CDH plugin cannot scale node group with processes "
101
"which have no master-processes run in cluster")
102
raise ex.NodeGroupCannotBeScaled(ng.name, msg)
105
def validate_existing_ng_scaling(cluster, existing):
106
scalable_processes = _get_scalable_processes()
108
for ng in cluster.node_groups:
109
if ng.id in existing:
110
if ng.count > existing[ng.id] and "datanode" in ng.node_processes:
111
dn_to_delete += ng.count - existing[ng.id]
113
if not set(ng.node_processes).issubset(scalable_processes):
114
msg = _("CDH plugin cannot scale nodegroup with processes: "
116
raise ex.NodeGroupCannotBeScaled(
117
ng.name, msg % {'processes': ' '.join(ng.node_processes)})
120
def _get_scalable_processes():
121
return ['DATANODE', 'NODEMANAGER']
124
def _get_inst_count(cluster, process):
125
return sum([ng.count for ng in u.get_node_groups(cluster, process)])