From c480b548eb95e3cd48e3b42f63b956725203807a Mon Sep 17 00:00:00 2001 From: rathnapandi Date: Mon, 4 Dec 2023 12:39:12 -0700 Subject: [PATCH] - debug quota test failures --- .../axway/apim/adapter/APIManagerAdapter.java | 4 +- .../adapter/apis/APIManagerAPIAdapter.java | 18 ++++++--- .../apim/api/export/impl/JsonAPIExporter.java | 19 ++++++---- .../actions/ManageClientOrganization.java | 34 ++++++++--------- .../apim/changeAction/ChangeTestAction.java | 37 +++++++++++++------ 5 files changed, 68 insertions(+), 44 deletions(-) diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java index 5a53ede88..66d84a150 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java @@ -233,10 +233,10 @@ public void loginToAPIManager() throws AppException { User user = getCurrentUser(); String role = getHigherRole(user); if (role.equals(ADMIN)) { - this.hasAdminAccount = true; + hasAdminAccount = true; // Also register this client as an Admin-Client } else if (role.equals(OADMIN)) { - this.usingOrgAdmin = true; + usingOrgAdmin = true; } } catch (IOException | URISyntaxException e) { throw new AppException("Can't login to API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e); diff --git a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java index 073d946d7..4977b7ed5 100644 --- a/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java +++ b/modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java @@ -945,6 +945,17 @@ public void upgradeAccessToNewerAPI(API apiToUpgradeAccess, API referenceAPI) th } } + public List addParam(API apiToUpgradeAccess, Boolean deprecateRefApi, Boolean retireRefApi, Long retirementDateRefAPI) { + List params = new ArrayList<>(); + params.add(new BasicNameValuePair("upgradeApiId", apiToUpgradeAccess.getId())); + if (deprecateRefApi != null) params.add(new BasicNameValuePair("deprecate", deprecateRefApi.toString())); + if (retireRefApi != null) params.add(new BasicNameValuePair("retire", retireRefApi.toString())); + if (retirementDateRefAPI != null) + params.add(new BasicNameValuePair("retirementDate", formatRetirementDate(retirementDateRefAPI))); + return params; + + } + public boolean upgradeAccessToNewerAPI(API apiToUpgradeAccess, API referenceAPI, Boolean deprecateRefApi, Boolean retireRefApi, Long retirementDateRefAPI) throws AppException { if (apiToUpgradeAccess.getState().equals(API.STATE_UNPUBLISHED)) { LOG.info("API to upgrade access has state unpublished."); @@ -959,12 +970,7 @@ public boolean upgradeAccessToNewerAPI(API apiToUpgradeAccess, API referenceAPI, LOG.debug("Upgrade access & subscriptions to API: {} {} ({})", apiToUpgradeAccess.getName(), apiToUpgradeAccess.getVersion(), apiToUpgradeAccess.getId()); try { URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/proxies/upgrade/" + referenceAPI.getId()).build(); - List params = new ArrayList<>(); - params.add(new BasicNameValuePair("upgradeApiId", apiToUpgradeAccess.getId())); - if (deprecateRefApi != null) params.add(new BasicNameValuePair("deprecate", deprecateRefApi.toString())); - if (retireRefApi != null) params.add(new BasicNameValuePair("retire", retireRefApi.toString())); - if (retirementDateRefAPI != null) - params.add(new BasicNameValuePair("retirementDate", formatRetirementDate(retirementDateRefAPI))); + List params = addParam(apiToUpgradeAccess, deprecateRefApi, retireRefApi, retirementDateRefAPI); HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); RestAPICall request = new POSTRequest(entity, uri); diff --git a/modules/apis/src/main/java/com/axway/apim/api/export/impl/JsonAPIExporter.java b/modules/apis/src/main/java/com/axway/apim/api/export/impl/JsonAPIExporter.java index aec5f3314..a699a859a 100644 --- a/modules/apis/src/main/java/com/axway/apim/api/export/impl/JsonAPIExporter.java +++ b/modules/apis/src/main/java/com/axway/apim/api/export/impl/JsonAPIExporter.java @@ -119,6 +119,17 @@ public void saveAPILocally(ExportAPI exportAPI, APIResultHandler apiResultHandle SimpleBeanPropertyFilter.serializeAllExcept("apiMethodId")) .setDefaultFilter(SimpleBeanPropertyFilter.serializeAllExcept()); mapper.setFilterProvider(filters); + writeContent(mapper, exportAPI, localFolder, configFile); + LOG.info("Successfully exported API: {} into folder: {}", exportAPI.getName(), localFolder.getAbsolutePath()); + if (!APIManagerAdapter.getInstance().hasAdminAccount()) { + LOG.warn("Export has been done with an Org-Admin account only. Export is restricted by the following: "); + LOG.warn("- No Quotas has been exported for the API"); + LOG.warn("- No Client-Organizations"); + LOG.warn("- Only subscribed applications from the Org-Admins organization"); + } + } + + public void writeContent(ObjectMapper mapper, ExportAPI exportAPI, File localFolder, String configFile) throws AppException { try { mapper.enable(SerializationFeature.INDENT_OUTPUT); if (EnvironmentProperties.PRINT_CONFIG_CONSOLE) { @@ -129,14 +140,6 @@ public void saveAPILocally(ExportAPI exportAPI, APIResultHandler apiResultHandle } catch (Exception e) { throw new AppException("Can't create API-Configuration file for API: '" + exportAPI.getName() + "' exposed on path: '" + exportAPI.getPath() + "'.", ErrorCode.UNXPECTED_ERROR, e); } - - LOG.info("Successfully exported API: {} into folder: {}", exportAPI.getName(), localFolder.getAbsolutePath()); - if (!APIManagerAdapter.getInstance().hasAdminAccount()) { - LOG.warn("Export has been done with an Org-Admin account only. Export is restricted by the following: "); - LOG.warn("- No Quotas has been exported for the API"); - LOG.warn("- No Client-Organizations"); - LOG.warn("- Only subscribed applications from the Org-Admins organization"); - } } private String getVHost(ExportAPI exportAPI) throws AppException { diff --git a/modules/apis/src/main/java/com/axway/apim/apiimport/actions/ManageClientOrganization.java b/modules/apis/src/main/java/com/axway/apim/apiimport/actions/ManageClientOrganization.java index 90c4e15b8..bfd9ab549 100644 --- a/modules/apis/src/main/java/com/axway/apim/apiimport/actions/ManageClientOrganization.java +++ b/modules/apis/src/main/java/com/axway/apim/apiimport/actions/ManageClientOrganization.java @@ -43,25 +43,25 @@ public void execute(boolean reCreation) throws AppException { if ((desiredState).isRequestForAllOrgs()) { LOG.info("Granting permission to all organizations"); apiManager.getApiAdapter().grantClientOrganization(getMissingOrgs(desiredState.getClientOrganizations(), actualState.getClientOrganizations()), actualState, true); + return; + } + List missingDesiredOrgs = getMissingOrgs(desiredState.getClientOrganizations(), actualState.getClientOrganizations()); + List removingActualOrgs = getMissingOrgs(actualState.getClientOrganizations(), desiredState.getClientOrganizations()); + removingActualOrgs.remove(desiredState.getOrganization());// Don't try to remove the Owning-Organization + if (missingDesiredOrgs.isEmpty()) { + if (desiredState.getClientOrganizations() != null) { + LOG.info("All desired organizations: {} have already access. Nothing to do.", desiredState.getClientOrganizations()); + } } else { - List missingDesiredOrgs = getMissingOrgs(desiredState.getClientOrganizations(), actualState.getClientOrganizations()); - List removingActualOrgs = getMissingOrgs(actualState.getClientOrganizations(), desiredState.getClientOrganizations()); - removingActualOrgs.remove(desiredState.getOrganization());// Don't try to remove the Owning-Organization - if (missingDesiredOrgs.isEmpty()) { - if (desiredState.getClientOrganizations() != null) { - LOG.info("All desired organizations: {} have already access. Nothing to do.", desiredState.getClientOrganizations()); - } + LOG.info("Granting access for organizations : {} to API : {}", missingDesiredOrgs, actualState.getName()); + apiManager.getApiAdapter().grantClientOrganization(missingDesiredOrgs, actualState, false); + } + if (!removingActualOrgs.isEmpty()) { + if (CoreParameters.getInstance().getClientOrgsMode().equals(CoreParameters.Mode.replace)) { + LOG.info("Removing access for organizations: {} from API: {}", removingActualOrgs, actualState.getName()); + apiManager.getAccessAdapter().removeClientOrganization(removingActualOrgs, actualState.getId()); } else { - LOG.info("Granting access for organizations : {} to API : {}", missingDesiredOrgs, actualState.getName()); - apiManager.getApiAdapter().grantClientOrganization(missingDesiredOrgs, actualState, false); - } - if (!removingActualOrgs.isEmpty()) { - if (CoreParameters.getInstance().getClientOrgsMode().equals(CoreParameters.Mode.replace)) { - LOG.info("Removing access for organizations: {} from API: {}", removingActualOrgs, actualState.getName()); - apiManager.getAccessAdapter().removeClientOrganization(removingActualOrgs, actualState.getId()); - } else { - LOG.info("NOT removing access for existing organizations: {} from API: {} as clientOrgsMode NOT set to replace.",removingActualOrgs,actualState.getName()); - } + LOG.info("NOT removing access for existing organizations: {} from API: {} as clientOrgsMode NOT set to replace.", removingActualOrgs, actualState.getName()); } } } diff --git a/modules/apis/src/test/java/com/axway/apim/changeAction/ChangeTestAction.java b/modules/apis/src/test/java/com/axway/apim/changeAction/ChangeTestAction.java index 8e7bae5de..114d6ab58 100644 --- a/modules/apis/src/test/java/com/axway/apim/changeAction/ChangeTestAction.java +++ b/modules/apis/src/test/java/com/axway/apim/changeAction/ChangeTestAction.java @@ -12,7 +12,7 @@ import java.util.List; public class ChangeTestAction extends AbstractTestAction { - + private static final Logger LOG = LoggerFactory.getLogger(ChangeTestAction.class); @Override @@ -31,7 +31,7 @@ public void doExecute(TestContext context) { try { useEnvironmentOnly = Boolean.parseBoolean(context.getVariable("useEnvironmentOnly")); } catch (Exception ignore) {} - + boolean enforce = false; boolean ignoreQuotas = false; boolean ignoreCache = false; @@ -39,12 +39,14 @@ public void doExecute(TestContext context) { String clientOrgsMode = null; String clientAppsMode = null; String quotaMode = null; - + String newBackend = null; String oldBackend = null; String name = null; - - try { + boolean useApiAdmin = false; + + + try { enforce = Boolean.parseBoolean(context.getVariable("enforce")); } catch (Exception ignore) {} try { @@ -74,12 +76,15 @@ public void doExecute(TestContext context) { try { oldBackend = context.getVariable("oldBackend"); } catch (Exception ignore) {} - - + try { + useApiAdmin = Boolean.parseBoolean(context.getVariable("useApiAdmin")); + } catch (Exception ignore) { + } + if(stage==null) { stage = "NOT_SET"; } - + List args = new ArrayList<>(); if(useEnvironmentOnly) { args.add("-s"); @@ -88,9 +93,19 @@ public void doExecute(TestContext context) { args.add("-h"); args.add(context.replaceDynamicContentInString("${apiManagerHost}")); args.add("-u"); - args.add(context.replaceDynamicContentInString("${oadminUsername1}")); - args.add("-p"); - args.add(context.replaceDynamicContentInString("${oadminPassword1}")); + if (useApiAdmin) { + LOG.info("API-Manager import is using user: '" + context.replaceDynamicContentInString("${apiManagerUser}") + "'"); + args.add(context.replaceDynamicContentInString("${apiManagerUser}")); + } + else { + LOG.info("API-Manager import is using user: '" + context.replaceDynamicContentInString("${oadminUsername1}") + "'"); + args.add(context.replaceDynamicContentInString("${oadminUsername1}")); + } + args.add("-p"); + if (useApiAdmin) + args.add(context.replaceDynamicContentInString("${apiManagerPass}")); + else + args.add(context.replaceDynamicContentInString("${oadminPassword1}")); args.add("-s"); args.add(stage); if(quotaMode!=null) {