Skip to content
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

Change API Provider #12189

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove the api path move logic
  • Loading branch information
shnrndk committed Nov 22, 2023
commit 583cdab1acdc7d71fa869ab416ab4f44ceb97224
Original file line number Diff line number Diff line change
Expand Up @@ -3751,49 +3751,22 @@ public String changeApiProvider(String providerName, String apiId, String org, M
String oldArtifactPath = GovernanceUtils.getArtifactPath(userRegistry, apiId);
Resource apiResource = userRegistry.get(oldArtifactPath);
if (apiResource != null) {
//userRegistry.beginTransaction();
userRegistry.beginTransaction();
GenericArtifactManager artifactManager = RegistryPersistenceUtil.getArtifactManager(userRegistry,
APIConstants.API_KEY);
if (artifactManager == null) {
String errorMessage = "Artifact manager is null when changing the provider name of " + apiId;
log.error(errorMessage);
throw new APIPersistenceException(errorMessage);
}
//Moving the registry file
GenericArtifact artifact = getAPIArtifact(apiId, userRegistry);
String oldProvider = artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
String newProvider = providerName;
String[] artifactPathChunks = oldArtifactPath.split(oldProvider);
String newArtifactApiPath = artifactPathChunks[0] + newProvider + artifactPathChunks[1];
userRegistry.move(oldArtifactPath, newArtifactApiPath);
String oldArtifactSwaggerPath = oldArtifactPath.replaceFirst("/api$",
"/swagger.json");
String newArtifactSwaggerPath = newArtifactApiPath.replaceFirst("/api$",
"/swagger.json");
userRegistry.move(oldArtifactSwaggerPath, newArtifactSwaggerPath);
int time=0;
while (!userRegistry.resourceExists(newArtifactSwaggerPath) &&
!userRegistry.resourceExists(newArtifactApiPath) || time > 5000) {
Thread.sleep(1000);
log.info("-------------Resource Not Existed-------------");
time += 1000;
}
Resource newAPIArtifact = userRegistry.get(newArtifactApiPath);
Resource newSwaggerArtifact = userRegistry.get(newArtifactSwaggerPath);
userRegistry.put(newArtifactApiPath,newAPIArtifact);
userRegistry.put(newArtifactSwaggerPath,newSwaggerArtifact);
//Thread.sleep(10000);
artifact = getAPIArtifact(apiId, userRegistry);
artifact.setAttribute(APIConstants.API_OVERVIEW_PROVIDER, newProvider);
artifact.setAttribute(APIConstants.API_OVERVIEW_PROVIDER, providerName);
artifactManager.updateGenericArtifact(artifact);

//userRegistry.commitTransaction();
userRegistry.commitTransaction();
transactionCommitted=true;
}
} catch (RegistryException e) {
throw new APIManagementException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
try {
if (userRegistry != null && !transactionCommitted) {
Expand Down