Skip to content

Commit

Permalink
- debug quota test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Dec 4, 2023
1 parent a32761f commit c480b54
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,17 @@ public void upgradeAccessToNewerAPI(API apiToUpgradeAccess, API referenceAPI) th
}
}

public List<NameValuePair> addParam(API apiToUpgradeAccess, Boolean deprecateRefApi, Boolean retireRefApi, Long retirementDateRefAPI) {
List<NameValuePair> 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.");
Expand All @@ -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<NameValuePair> 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<NameValuePair> params = addParam(apiToUpgradeAccess, deprecateRefApi, retireRefApi, retirementDateRefAPI);

HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
RestAPICall request = new POSTRequest(entity, uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Organization> missingDesiredOrgs = getMissingOrgs(desiredState.getClientOrganizations(), actualState.getClientOrganizations());
List<Organization> 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<Organization> missingDesiredOrgs = getMissingOrgs(desiredState.getClientOrganizations(), actualState.getClientOrganizations());
List<Organization> 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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;

public class ChangeTestAction extends AbstractTestAction {

private static final Logger LOG = LoggerFactory.getLogger(ChangeTestAction.class);

@Override
Expand All @@ -31,20 +31,22 @@ public void doExecute(TestContext context) {
try {
useEnvironmentOnly = Boolean.parseBoolean(context.getVariable("useEnvironmentOnly"));
} catch (Exception ignore) {}

boolean enforce = false;
boolean ignoreQuotas = false;
boolean ignoreCache = false;
boolean changeOrganization = false;
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 {
Expand Down Expand Up @@ -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<String> args = new ArrayList<>();
if(useEnvironmentOnly) {
args.add("-s");
Expand All @@ -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) {
Expand Down

0 comments on commit c480b54

Please sign in to comment.