|
1 | 1 | """
|
2 |
| -Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. |
3 | 3 | Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
4 | 4 | """
|
| 5 | +import os |
| 6 | + |
5 | 7 | from sets import Set
|
6 | 8 |
|
7 | 9 | from java.io import IOException
|
8 | 10 | from java.net import URI
|
9 | 11 | from java.security import NoSuchAlgorithmException
|
10 | 12 |
|
| 13 | +from oracle.weblogic.deploy.deploy import DeployException |
11 | 14 | from oracle.weblogic.deploy.util import FileUtils
|
| 15 | +from oracle.weblogic.deploy.util import StringUtils |
12 | 16 | from oracle.weblogic.deploy.util import PyWLSTException
|
13 | 17 | from oracle.weblogic.deploy.util import WLSDeployArchive
|
14 | 18 |
|
15 | 19 | from wlsdeploy.aliases.location_context import LocationContext
|
| 20 | +from wlsdeploy.aliases.model_constants import CLUSTER |
| 21 | +from wlsdeploy.aliases.model_constants import DYNAMIC_CLUSTER_SIZE |
| 22 | +from wlsdeploy.aliases.model_constants import DYNAMIC_SERVERS |
16 | 23 | from wlsdeploy.aliases.model_constants import FILE_URI
|
17 | 24 | from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS
|
18 | 25 | from wlsdeploy.aliases.model_constants import JDBC_RESOURCE
|
19 | 26 | from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE
|
| 27 | +from wlsdeploy.aliases.model_constants import SERVER |
| 28 | +from wlsdeploy.aliases.model_constants import SERVER_NAME_PREFIX |
| 29 | +from wlsdeploy.aliases.model_constants import SERVER_NAME_START_IDX |
| 30 | +from wlsdeploy.aliases.validation_codes import ValidationCodes |
20 | 31 | from wlsdeploy.aliases.wlst_modes import WlstModes
|
21 | 32 | from wlsdeploy.exception import exception_helper
|
22 | 33 | from wlsdeploy.exception.expection_types import ExceptionType
|
@@ -415,3 +426,143 @@ def get_file_hash(file_name):
|
415 | 426 | raise ex
|
416 | 427 | _logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
|
417 | 428 | return result
|
| 429 | + |
| 430 | + |
| 431 | +def get_cluster_for_server(server_name, aliases): |
| 432 | + """ |
| 433 | + Get the Cluster name for the existing server name for additional information to mine for the update action. |
| 434 | + :param server_name: name of the server |
| 435 | + :param aliases: alias context instance |
| 436 | + :return: cluster name: name of the cluster the server belongs to, or None if stand-alone or server does not exist |
| 437 | + """ |
| 438 | + _method_name = 'get_cluster_for_server' |
| 439 | + _logger.entering(server_name, class_name=_class_name, method_name=_method_name) |
| 440 | + location = LocationContext() |
| 441 | + location.append_location(SERVER) |
| 442 | + name_token = aliases.get_name_token(location) |
| 443 | + location.add_name_token(name_token, server_name) |
| 444 | + attr_path = aliases.get_wlst_attributes_path(location) |
| 445 | + cluster_name = None |
| 446 | + try: |
| 447 | + _wlst_helper.cd(attr_path) |
| 448 | + cluster_name = _wlst_helper.get(CLUSTER) |
| 449 | + except DeployException, de: |
| 450 | + _logger.fine('WLSDPLY-09205', server_name, str(location), de.getLocalizedMessage, |
| 451 | + SERVER, class_name=_class_name, method_name=_method_name) |
| 452 | + _logger.exiting(result=cluster_name, class_name=_class_name, method_name=_method_name) |
| 453 | + return cluster_name |
| 454 | + |
| 455 | + |
| 456 | +def list_restarts(model_context): |
| 457 | + """ |
| 458 | + Get the list of restarts and save this list in format to restart.file |
| 459 | + in the -output_dirs location. If the output_dirs is not included, bypass |
| 460 | + writing to the restart file. |
| 461 | + :param model_context: instance of the tool model context |
| 462 | + """ |
| 463 | + _method_name = 'list_restarts' |
| 464 | + _logger.entering(model_context.get_output_dir(), class_name=_class_name, method_name=_method_name) |
| 465 | + restart_list = get_list_of_restarts() |
| 466 | + output_dirs = model_context.get_output_dir() |
| 467 | + if output_dirs is not None: |
| 468 | + file_name = os.path.join(output_dirs, 'restart.file') |
| 469 | + pw = FileUtils.getPrintWriter(file_name) |
| 470 | + for entry in restart_list: |
| 471 | + line = '%s:%s:%s:%s' % (entry[0], entry[1], entry[2], entry[3]) |
| 472 | + _logger.finer('WLSDPLY-09208', line, class_name=_class_name, method_name=_method_name) |
| 473 | + pw.println(line) |
| 474 | + pw.close() |
| 475 | + _logger.exiting(class_name=_class_name, method_name=_method_name) |
| 476 | + |
| 477 | + |
| 478 | +def get_list_of_restarts(): |
| 479 | + """ |
| 480 | + Return the restart checklist from the online domain instance. Log each instance of the restart checklist |
| 481 | + :return: String buffer of restart information |
| 482 | + """ |
| 483 | + _method_name = 'get_list_of_restarts' |
| 484 | + restart_list = [] |
| 485 | + _wlst_helper.cd('/') |
| 486 | + cmo = _wlst_helper.get_cmo() |
| 487 | + for server in _wlst_helper.get_server_runtimes(): |
| 488 | + resources = server.getPendingRestartSystemResources() |
| 489 | + is_restart = server.isRestartRequired() |
| 490 | + if len(resources) > 0 or is_restart: |
| 491 | + server_name = server.getName() |
| 492 | + cluster = server.getClusterRuntime() |
| 493 | + cluster_name = '' |
| 494 | + if cluster is not None: |
| 495 | + cluster_name = cluster.getName() |
| 496 | + prt_cluster = cluster_name |
| 497 | + if cluster_name == '': |
| 498 | + prt_cluster = 'standalone' |
| 499 | + for resource in server.getPendingRestartSystemResources(): |
| 500 | + line = list() |
| 501 | + line.append(cluster_name) |
| 502 | + line.append(server_name) |
| 503 | + line.append(resource) |
| 504 | + value = cmo.lookupSystemResource(resource) |
| 505 | + res_type = '' |
| 506 | + if value is not None: |
| 507 | + res_type = value.getType() |
| 508 | + line.append(res_type) |
| 509 | + restart_list.append(line) |
| 510 | + _logger.warning('WLSDPLY-09207', resource, res_type, server_name, prt_cluster, |
| 511 | + class_name=_class_name, method_name=_method_name) |
| 512 | + if is_restart: |
| 513 | + line = list() |
| 514 | + line.append(cluster_name) |
| 515 | + line.append(server_name) |
| 516 | + line.append('') |
| 517 | + line.append('') |
| 518 | + restart_list.append(line) |
| 519 | + _logger.warning('WLSDPLY-09206', server_name, prt_cluster, |
| 520 | + class_name=_class_name, method_name=_method_name) |
| 521 | + return restart_list |
| 522 | + |
| 523 | + |
| 524 | +def check_if_dynamic_cluster(server_name, cluster_name, aliases): |
| 525 | + """ |
| 526 | + Determine if the server is part of a dynamic cluster. |
| 527 | + :param server_name: Name of the server to check |
| 528 | + :param cluster_name: Name of the cluster the server belongs to, or None if stand-alone |
| 529 | + :param aliases: aliases context instance |
| 530 | + :return: True if part of a dynamic cluster |
| 531 | + """ |
| 532 | + _method_name = 'check_if_dynamic_cluster' |
| 533 | + # check wls version first either here or before caller. preferably here |
| 534 | + location = LocationContext() |
| 535 | + location.append_location(CLUSTER) |
| 536 | + location.add_name_token(aliases.get_name_token(location), cluster_name) |
| 537 | + attr_path = aliases.get_wlst_attributes_path(location) |
| 538 | + |
| 539 | + try: |
| 540 | + _wlst_helper.cd(attr_path) |
| 541 | + except DeployException, de: |
| 542 | + _logger.fine('WLSDPLY-09205', cluster_name, str(location), de.getLocalizedMessage, |
| 543 | + CLUSTER, class_name=_class_name, method_name=_method_name) |
| 544 | + return True |
| 545 | + location.append_location(DYNAMIC_SERVERS) |
| 546 | + location.add_name_token(aliases.get_name_token(location), cluster_name) |
| 547 | + attr_path = aliases.get_wlst_attributes_path(location) |
| 548 | + try: |
| 549 | + _wlst_helper.cd(attr_path) |
| 550 | + except DeployException: |
| 551 | + return False |
| 552 | + attr_name = aliases.get_wlst_attribute_name(location, DYNAMIC_CLUSTER_SIZE) |
| 553 | + dynamic_size = _wlst_helper.get(attr_name) |
| 554 | + attr_name = aliases.get_wlst_attribute_name(location, SERVER_NAME_PREFIX) |
| 555 | + prefix = _wlst_helper.get(attr_name) |
| 556 | + starting = 1 |
| 557 | + present, __ = aliases.is_valid_model_attribute_name(location, SERVER_NAME_START_IDX) |
| 558 | + if present == ValidationCodes.VALID: |
| 559 | + attr_name = aliases.get_model_attribute_name(location, SERVER_NAME_START_IDX) |
| 560 | + starting = _wlst_helper.get(attr_name) |
| 561 | + if dynamic_size > 0 and prefix is not None and server_name.startswith(prefix): |
| 562 | + split_it = server_name.split(prefix) |
| 563 | + if len(split_it) == 2: |
| 564 | + number = StringUtils.stringToInteger(split_it[1].strip()) |
| 565 | + if number is not None and starting <= number < (dynamic_size + starting): |
| 566 | + return True |
| 567 | + return False |
| 568 | + |
0 commit comments