From a0b85879490cd0a503262b94cc79ee19280961a4 Mon Sep 17 00:00:00 2001 From: Dmitriy Shamatrin Date: Tue, 25 May 2021 15:12:27 +0300 Subject: [PATCH] Initial implementation of Check Entities For Existence procedure --- build.gradle | 4 +- src/main/resources/project/ec_setup.pl | 14 +- src/main/resources/project/manifest.xml | 33 +++- .../Entity/CheckEntityForExistence.xml | 94 +++++++++ .../project/procedures_with_credentials.json | 4 + src/main/resources/project/project.xml | 184 ++++++++++++++++++ .../server/Entity/checkEntityForExistence.pl | 80 ++++++++ .../Entity/check_entity_for_existence.py | 28 +++ .../project/wsadmin_scripts/preamble.py | 16 ++ 9 files changed, 450 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/project/parameterForms/Entity/CheckEntityForExistence.xml create mode 100644 src/main/resources/project/server/Entity/checkEntityForExistence.pl create mode 100644 src/main/resources/project/wsadmin_scripts/Entity/check_entity_for_existence.py diff --git a/build.gradle b/build.gradle index a3ed6d97..16139378 100644 --- a/build.gradle +++ b/build.gradle @@ -22,8 +22,8 @@ repositories { maven { url 'https://nexus-internal.cloudbees.com/content/groups/mirror' credentials { - username = nexusUsername - password = nexusPassword + username = System.getenv('NEXUS_USERNAME') ?: nexusUsername + password = System.getenv('NEXUS_PASSWORD') ?: nexusPassword } } } diff --git a/src/main/resources/project/ec_setup.pl b/src/main/resources/project/ec_setup.pl index 611c361d..86a319ec 100644 --- a/src/main/resources/project/ec_setup.pl +++ b/src/main/resources/project/ec_setup.pl @@ -433,6 +433,12 @@ category => "Application Server" ); +my %checkEntityForExistence = ( + label => "WebSphere - Check Entity for Existence", + procedure => 'CheckEntityForExistence', + description => 'Check whether entity exists', + category => 'Application Server', +); $batch->deleteProperty("/server/ec_customEditors/pickerStep/WebSphere - Start App"); $batch->deleteProperty("/server/ec_customEditors/pickerStep/WebSphere - Stop App"); @@ -523,6 +529,10 @@ $batch->deleteProperty("/server/ec_customEditors/pickerStep/WebSphere - Create First Cluster Member"); $batch->deleteProperty("/server/ec_customEditors/pickerStep/WebSphere - Create Cluster Members"); +# Check Entities for Existence +$batch->deleteProperty("/server/ec_customEditors/pickerStep/WebSphere - Check Entity for Existence"); + + @::createStepPickerSteps = ( \%checkPageStatus, \%checkServerStatus, \%startServer, \%stopServer, @@ -566,7 +576,9 @@ \%createCluster, # Create 1st cluster member # Uncomment after 2.5.0 release - \%createFirstClusterMember, \%createClusterMembers + \%createFirstClusterMember, \%createClusterMembers, + # Check Entity for existence + \%checkEntityForExistence ); if ($upgradeAction eq "upgrade") { diff --git a/src/main/resources/project/manifest.xml b/src/main/resources/project/manifest.xml index e3e77062..ddae9010 100644 --- a/src/main/resources/project/manifest.xml +++ b/src/main/resources/project/manifest.xml @@ -370,10 +370,11 @@ conf/createConfiguration.pl - - //procedure[procedureName="CreateConfiguration"]/step[stepName="CreateAndAttachCredential"]/command - conf/createAndAttachCredential.pl - + + + + + //procedure[procedureName="CreateConfiguration"]/propertySheet/property[propertyName="ec_stepsWithAttachedCredentials"]/value @@ -938,6 +939,30 @@ + + + + + + //procedure[procedureName="CheckEntityForExistence"]/propertySheet/property[propertyName="ec_parameterForm"]/value + parameterForms/Entity/CheckEntityForExistence.xml + + + + //property[propertyName="check_entity_for_existence.py"]/value + wsadmin_scripts/Entity/check_entity_for_existence.py + + + + //procedure[procedureName="CheckEntityForExistence"]/step[stepName="CheckEntityForExistence"]/command + server/Entity/checkEntityForExistence.pl + + + + + + + diff --git a/src/main/resources/project/parameterForms/Entity/CheckEntityForExistence.xml b/src/main/resources/project/parameterForms/Entity/CheckEntityForExistence.xml new file mode 100644 index 00000000..84e3e775 --- /dev/null +++ b/src/main/resources/project/parameterForms/Entity/CheckEntityForExistence.xml @@ -0,0 +1,94 @@ + + + https://docs.cloudbees.com/docs/cloudbees-cd/latest/plugins/ec-websphere#CheckEntityForExistence + + entry + + + 1 + + configname + /plugins/@PLUGIN_NAME@/project/websphere_cfgs + Name of the configuration to be used. URL, port and credentials are retrieved from the given configuration. To view or create a new configuration, go to the Administration -> Plugins tab, and select 'Configure' action for @PLUGIN_KEY@ plugin. + Name of the configuration to be used. URL, port and credentials are retrieved from the given configuration. + 1 + + + + wasEntityName + entry + 1 + Entity Name + + + + wasEntityType + select + 1 + The Entity Type + + + + + + + wasEntityScope + entry + 1 + Entity Scope + + + + wasProcedureHandlingLogic + select + 1 + Procedure Handling Logic + + + + + + + + wasOutputPropertyPath + entry + 0 + + Output Property Path + + + diff --git a/src/main/resources/project/procedures_with_credentials.json b/src/main/resources/project/procedures_with_credentials.json index ea89696d..322171d9 100644 --- a/src/main/resources/project/procedures_with_credentials.json +++ b/src/main/resources/project/procedures_with_credentials.json @@ -230,5 +230,9 @@ { "stepName": "CreateClusterMembers", "procedureName": "CreateClusterMembers" + }, + { + "stepName": "CheckEntityForExistence", + "procedureName": "CheckEntityForExistence" } ] diff --git a/src/main/resources/project/project.xml b/src/main/resources/project/project.xml index 7ccb2f7b..771ea32d 100644 --- a/src/main/resources/project/project.xml +++ b/src/main/resources/project/project.xml @@ -641,6 +641,11 @@ list_cluster_members.py + + + check_entity_for_existence.py + + @@ -13885,5 +13890,184 @@ + + + + + CheckEntityForExistence + Checks whether entity does exist + websphere-check-entity-for-existence-$[jobId] + + + @PLUGIN_KEY@-@PLUGIN_VERSION@ + + + ec_parameterForm + 1 + + + + ec_customEditorData + + + parameters + + + + configname + + + formType + 1 + standard + + + + + wasEntityName + + + formType + 1 + standard + + + + + wasEntityType + + + formType + 1 + standard + + + + + + wasEntityScope + + + formType + 1 + standard + + + + + + wasProcedureHandlingLogic + + + formType + 1 + standard + + + + + + wasOutputPropertyPath + + + formType + 1 + standard + + + + + + + + + + + + configname + + Name of the configuration to be used. URL, port and credentials are retrieved from the given configuration. + To view or create a new configuration, + go to the Administration -> Plugins tab, and select 'Configure' action for @PLUGIN_KEY@ plugin. + 1 + entry + + + + wasEntityName + + WAS Entity Type To Check + 1 + entry + + + wasEntityType + + WAS Entity Type To Check + 1 + entry + + + + wasEntityScope + + WAS entity scope + 1 + entry + + + + wasProcedureHandlingLogic + + WAS Procedure Handling Logic + 0 + entry + + + + wasOutputPropertyPath + + WAS Output Property Path + 1 + entry + + + + + CheckEntityForExistence + 0 + 0 + + + failProcedure + 0 + + 0 + + 0 + + 0 + ec-perl + 5 + minutes + + + CheckEntityForExistence + @PLUGIN_KEY@-@PLUGIN_VERSION@ + + + ec_customEditorData + + + formType + 1 + command + + + + + + + diff --git a/src/main/resources/project/server/Entity/checkEntityForExistence.pl b/src/main/resources/project/server/Entity/checkEntityForExistence.pl new file mode 100644 index 00000000..f4f27029 --- /dev/null +++ b/src/main/resources/project/server/Entity/checkEntityForExistence.pl @@ -0,0 +1,80 @@ +# +# Copyright 2015 Electric Cloud, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +use strict; +use warnings; +use ElectricCommander; +use ElectricCommander::PropMod qw(/myProject/modules); +use WebSphere::WebSphere; +use WebSphere::Util; +use Data::Dumper; + +### Input parameters +my $handling_logic = '$[wasProcedureHandlingLogic]'; +my $entity_type = '$[wasEntityType]'; +my $entity_name = '$[wasEntityName]'; +my $entity_scope = '$[wasEntityScope]'; +### End of input parameters +my $base_message = sprintf( + "Entity %s (type: %s) in scope (%s) ", + $entity_name, + $entity_type, + $entity_scope +); +my $entity_does_not_exist_message = $base_message . 'does not exist.'; +my $entity_exists_message = $base_message . 'exists'; + +my $success_message = $base_message . 'checked. See properties and output parameters for results.'; +my $error_message = 'Failed to check ' . lcfirst($base_message) . ' for existence'; + +if ($handling_logic eq 'failIfExists') { + ($success_message, $error_message) = ($entity_does_not_exist_message, $entity_exists_message); +} +elsif ($handling_logic eq 'failIfDoesNotExist') { + ($error_message, $success_message) = ($entity_does_not_exist_message, $entity_exists_message); +} + +my $ec = ElectricCommander->new(); +$ec->abortOnError(0); + +my $opts = { + disabled_wsadmin_check => 0 +}; + +my $websphere = WebSphere::WebSphere->new($ec, '', '', $opts); + +$websphere->{jobStepId} = '$[jobStepId]'; + + +my $step_params = { + target => { + pipeline => 'Check Entity For Existence Result:', + success_summary => $success_message, + error_summary => $error_message + }, + jython_script => { + path => 'check_entity_for_existence.py', + } +}; + +eval { + $websphere->run_step($websphere->config_values()->{wsadminabspath}, $step_params); + 1; +} or do { + my $exception = $@; + rtrim($exception); + $websphere->bail_out($exception); +}; diff --git a/src/main/resources/project/wsadmin_scripts/Entity/check_entity_for_existence.py b/src/main/resources/project/wsadmin_scripts/Entity/check_entity_for_existence.py new file mode 100644 index 00000000..065926f6 --- /dev/null +++ b/src/main/resources/project/wsadmin_scripts/Entity/check_entity_for_existence.py @@ -0,0 +1,28 @@ +$[/myProject/wsadmin_scripts/preamble.py] + +### Script input parameters +entityType = '$[wasEntityType]' +entityName = '$[wasEntityName]' +entityScope = '$[wasEntityScope]' +handlingLogic = '$[wasProcedureHandlingLogic]' +outputProperty = '$[wasOutputPropertyPath]' +### End of input parameters + + +allowedEntities = ['DataSource', 'Library', 'JavaVirtualMachine'] +allowedLogics = ['failIfExists', 'failIfDoesNotExist', 'pass'] + +if entityType not in allowedEntities: + logError("Entity type %s is not allowed. Allowed types are: %s") % (entityType, allowedEntities) + os._exit(1) + +if handlingLogic not in allowedLogics: + logError("Logic %s is not allowed. Allowed handling logics are: %s") % (handlingLogic, allowedLogics) + os._exit(1) + +try: + entityExists = checkEntityForExistence(entityScope, entityType, entityName) + forwardData("Entity exists: " + str(entityExists)) +except: + forwardException(getExceptionMsg()) + sys.exit(1) diff --git a/src/main/resources/project/wsadmin_scripts/preamble.py b/src/main/resources/project/wsadmin_scripts/preamble.py index e42d5666..52113c96 100644 --- a/src/main/resources/project/wsadmin_scripts/preamble.py +++ b/src/main/resources/project/wsadmin_scripts/preamble.py @@ -678,4 +678,20 @@ def getClusterNotFoundSuggestion(): retval = "Available clusters: " + retval return retval +def checkEntityForExistence(entityScope, entityType, entityName): + currentEntities = AdminConfig.list(entityType, AdminConfig.getid(entityScope)).splitlines() + found = False + + for e in currentEntities: + if entityName == AdminConfig.showAttribute(e, "name"): + found = True + + if found: + print "the entity does exist" + found = True + else: + print "the entity does not exist" + + print "Returning true..."; + return found # def isServerBelongsToCluster