-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding the .ts file for commands/internal/container/prestop #3110
base: v2.x/staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
This program and the accompanying materials are made available | ||
under the terms of the Eclipse Public License v2.0 which | ||
accompanies this distribution, and is available at | ||
https://www.eclipse.org/legal/epl-v20.html | ||
|
||
SPDX-License-Identifier: EPL-2.0 | ||
|
||
Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
import * as std from 'std'; | ||
import * as fs from '../../../../libs/fs'; | ||
import * as common from '../../../../libs/common'; | ||
import * as node from '../../../../libs/node'; | ||
import * as shell from '../../../../libs/shell'; | ||
import * as config from '../../../../libs/config'; | ||
import * as component from '../../../../libs/component'; | ||
|
||
export function execute() { | ||
node.requireNode(); | ||
|
||
let pod_name = shell.execOutSync('hostname', '-s').out?.toLowerCase(); | ||
|
||
common.printLevel0Message('Delete APIML static definitions written by current pod ' + pod_name); | ||
// Validation | ||
common.requireZoweYaml(); | ||
|
||
//load environment | ||
config.loadEnvironmentVariables(); | ||
|
||
if (!std.getenv('ZWE_RUN_IN_CONTAINER')){ | ||
common.printErrorAndExit('Error ZWEL0123E: This function is only available in Zowe Containerization deployment.', undefined, 157); | ||
} | ||
|
||
let zwe_static_definition_dir = std.getenv('ZWE_STATIC_DEFINITIONS_DIR'); | ||
let zwe_cli_parameter_hs_instance = std.getenv('ZWE_CLI_PARAMETER_HA_INSTANCE'); | ||
if(fs.directoryExists(zwe_static_definition_dir) && pod_name !== undefined){ | ||
let result = shell.execOutSync('sh', '-c', `cd ${zwe_cli_parameter_hs_instance} && ls -l 2>&1`); | ||
if (result.out) { | ||
common.printMessage("- deleting"); | ||
shell.execOutSync('sh', '-c', `rm -f *.${zwe_cli_parameter_hs_instance}.* 2>&1`); | ||
common.printMessage("- refreshing api catalog"); | ||
let apicatalog_host = `api-catalog-service.${std.getenv('ZWE_POD_NAMESPACE')? std.getenv('ZWE_POD_NAMESPACE'): 'zowe'}.svc.${std.getenv('ZWE_POD_CLUSTERNAME')? std.getenv('ZWE_POD_CLUSTERNAME'): 'cluster.local'}` | ||
let success =component.refreshStaticRegistration(apicatalog_host, | ||
std.getenv('ZWE_components_api_catalog_port'), | ||
std.getenv('ZWE_zowe_certificate_pem_key'), | ||
std.getenv('ZWE_zowe_certificate_pem_certificate'), | ||
std.getenv('ZWE_zowe_certificate_pem_certificateAuthorities')); | ||
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these come from zowe.yaml.
if something is required by schema, you can guarantee it is in the object ZOWE_CONFIG there. but, a lot of these parameters are marked as optional (on purpose or accident) so we need to check them. |
||
if (success) { | ||
common.printFormattedDebug("ZWELS", "zwe-internal-container-prestop,execute", ` refreshStaticRegistration success`); | ||
} else { | ||
common.printFormattedError("Error ZWEL0142E", "zwe-internal-container-prestop,execute", `processComponentDiscoverySharedLibs failure`); | ||
} | ||
} else { | ||
common.printMessage("- nothing to delete"); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bracket in a weird place? |
||
} | ||
} | ||
|
||
|
||
// exit message | ||
common.printLevel1Message(`APIML static registrations are refreshed successfully.`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you may not want this right here. in the shell script, it was assumed most everything required node.
we see in the library file that the catalog thing uses curl.js... so why not put the requireNode() over there
i believe the requireNode() function caches the answer about if node exists, so if you call it multiple times it should not harm performance.