~ubuntu-branches/ubuntu/vivid/sahara/vivid-proposed

« back to all changes in this revision

Viewing changes to sahara/plugins/cdh/validation.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-24 16:34:46 UTC
  • Revision ID: package-import@ubuntu.com-20140924163446-8gu3zscu5e3n9lr2
Tags: upstream-2014.2~b3
ImportĀ upstreamĀ versionĀ 2014.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2014 Mirantis Inc.
 
2
#
 
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
 
6
#
 
7
#    http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
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
 
12
# implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
 
 
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
 
24
 
 
25
LOG = logging.getLogger(__name__)
 
26
 
 
27
 
 
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."))
 
33
 
 
34
    mng_count = _get_inst_count(cluster, 'MANAGER')
 
35
    if mng_count != 1:
 
36
        raise ex.InvalidComponentCountException('MANAGER', 1, mng_count)
 
37
 
 
38
    nn_count = _get_inst_count(cluster, 'NAMENODE')
 
39
    if nn_count != 1:
 
40
        raise ex.InvalidComponentCountException('NAMENODE', 1, nn_count)
 
41
 
 
42
    snn_count = _get_inst_count(cluster, 'SECONDARYNAMENODE')
 
43
    if snn_count != 1:
 
44
        raise ex.InvalidComponentCountException('SECONDARYNAMENODE', 1,
 
45
                                                snn_count)
 
46
 
 
47
    rm_count = _get_inst_count(cluster, 'RESOURCEMANAGER')
 
48
    if rm_count not in [0, 1]:
 
49
        raise ex.InvalidComponentCountException('RESOURCEMANAGER', '0 or 1',
 
50
                                                rm_count)
 
51
 
 
52
    hs_count = _get_inst_count(cluster, 'JOBHISTORY')
 
53
    if hs_count not in [0, 1]:
 
54
        raise ex.InvalidComponentCountException('JOBHISTORY', '0 or 1',
 
55
                                                hs_count)
 
56
 
 
57
    if rm_count > 0 and hs_count < 1:
 
58
        raise ex.RequiredServiceMissingException('JOBHISTORY',
 
59
                                                 required_by='RESOURCEMANAGER')
 
60
 
 
61
    nm_count = _get_inst_count(cluster, 'NODEMANAGER')
 
62
    if rm_count == 0:
 
63
        if nm_count > 0:
 
64
            raise ex.RequiredServiceMissingException('RESOURCEMANAGER',
 
65
                                                     required_by='NODEMANAGER')
 
66
 
 
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',
 
71
                                                oo_count)
 
72
 
 
73
    if oo_count == 1:
 
74
        if dn_count < 1:
 
75
            raise ex.RequiredServiceMissingException(
 
76
                'DATANODE', required_by='OOZIE_SERVER')
 
77
 
 
78
        if nm_count < 1:
 
79
            raise ex.RequiredServiceMissingException(
 
80
                'NODEMANAGER', required_by='OOZIE_SERVER')
 
81
 
 
82
        if hs_count != 1:
 
83
            raise ex.RequiredServiceMissingException(
 
84
                'JOBHISTORY', required_by='OOZIE_SERVER')
 
85
 
 
86
 
 
87
def validate_additional_ng_scaling(cluster, additional):
 
88
    rm = cu.get_resourcemanager(cluster)
 
89
    scalable_processes = _get_scalable_processes()
 
90
 
 
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: "
 
95
                    "%(processes)s")
 
96
            raise ex.NodeGroupCannotBeScaled(
 
97
                ng.name, msg % {'processes': ' '.join(ng.node_processes)})
 
98
 
 
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)
 
103
 
 
104
 
 
105
def validate_existing_ng_scaling(cluster, existing):
 
106
    scalable_processes = _get_scalable_processes()
 
107
    dn_to_delete = 0
 
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]
 
112
 
 
113
            if not set(ng.node_processes).issubset(scalable_processes):
 
114
                msg = _("CDH plugin cannot scale nodegroup with processes: "
 
115
                        "%(processes)s")
 
116
                raise ex.NodeGroupCannotBeScaled(
 
117
                    ng.name, msg % {'processes': ' '.join(ng.node_processes)})
 
118
 
 
119
 
 
120
def _get_scalable_processes():
 
121
    return ['DATANODE', 'NODEMANAGER']
 
122
 
 
123
 
 
124
def _get_inst_count(cluster, process):
 
125
    return sum([ng.count for ng in u.get_node_groups(cluster, process)])