better app deletion
This commit is contained in:
parent
001bbedced
commit
8d16d21dc7
@ -13,9 +13,9 @@ import cz.trask.migration.AbstractProcess;
|
||||
import cz.trask.migration.model.HttpResponse;
|
||||
import cz.trask.migration.model.TokenResponse;
|
||||
import cz.trask.migration.model.v32.ApplicationDetail;
|
||||
import cz.trask.migration.model.v32.ApplicationList;
|
||||
import cz.trask.migration.model.v45.ApplicationCreateRequest;
|
||||
import cz.trask.migration.model.v45.ApplicationCreateResponse;
|
||||
import cz.trask.migration.model.v45.ApplicationListResponse45;
|
||||
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
|
||||
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
|
||||
import io.apicurio.registry.rest.v2.beans.SearchedArtifact;
|
||||
@ -84,9 +84,10 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
.readValue(content, ApplicationDetail.class);
|
||||
ApplicationCreateRequest appCreateRequest = mapAppDetailToCreateRequest(appDetail);
|
||||
byte[] data = mapper.writeValueAsBytes(appCreateRequest);
|
||||
log.info(" - Prepared application data for WSO2: {} bytes", data.length);
|
||||
log.info(" - Application {} with owner {} prepared for WSO2 import", appDetail.getName(),
|
||||
appDetail.getOwner());
|
||||
|
||||
deleteWso2ApplicationIfExists(appDetail.getName(), tokenResponse);
|
||||
deleteWso2ApplicationIfExists(appDetail, tokenResponse);
|
||||
|
||||
HttpResponse response = publishAppToWso2(appDetail.getName(), data, tokenResponse);
|
||||
|
||||
@ -114,13 +115,14 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteWso2ApplicationIfExists(String appName, TokenResponse tokenResponse) {
|
||||
private void deleteWso2ApplicationIfExists(ApplicationDetail appDetail, TokenResponse tokenResponse) {
|
||||
|
||||
// Resolve application id by name first (WSO2 Admin API works with applicationId in paths)
|
||||
String resolvedAppId = getApplicationIdByName(config.getTarget().getAdminApiUrl(), appName, tokenResponse);
|
||||
// Resolve application id by name first (WSO2 Admin API works with applicationId
|
||||
// in paths)
|
||||
String resolvedAppId = getExistingApplicationId(config.getTarget().getAdminApiUrl(), appDetail, tokenResponse);
|
||||
|
||||
if (resolvedAppId == null) {
|
||||
log.warn(" - Application {} not found in WSO2, cannot delete", appName);
|
||||
log.warn(" - Application {} not found in WSO2, cannot delete", appDetail.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -133,18 +135,20 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
HttpResponse response = makeRequest("DELETE", endpoint, httpHeaders, null);
|
||||
|
||||
if (response.getResponseCode() == 200 || response.getResponseCode() == 204) {
|
||||
log.info(" - Application {} (id={}) deleted successfully from WSO2", appName, resolvedAppId);
|
||||
log.info(" - Application {} (id={}) deleted successfully from WSO2", appDetail.getName(),
|
||||
resolvedAppId);
|
||||
} else {
|
||||
log.info(" - Application {} (id={}) deletion from WSO2 returned response code {}",
|
||||
appName, resolvedAppId, response.getResponseCode());
|
||||
appDetail.getName(), resolvedAppId, response.getResponseCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("IO error while deleting Application {} (id={}): {}", appName, resolvedAppId,
|
||||
log.error("IO error while deleting Application {} (id={}): {}", appDetail.getName(), resolvedAppId,
|
||||
e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getApplicationIdByName(String adminApiUrl, String appName, TokenResponse tokenResponse) {
|
||||
private String getExistingApplicationId(String adminApiUrl, ApplicationDetail appDetail,
|
||||
TokenResponse tokenResponse) {
|
||||
try {
|
||||
String url = adminApiUrl.concat(String.format("/applications"));
|
||||
|
||||
@ -160,17 +164,18 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
return null;
|
||||
}
|
||||
|
||||
ApplicationList listOfApps = mapper.readValue(response.getResponse(), ApplicationList.class);
|
||||
ApplicationListResponse45 listOfApps = mapper.readValue(response.getResponse(),
|
||||
ApplicationListResponse45.class);
|
||||
|
||||
if (listOfApps != null && listOfApps.getList() != null) {
|
||||
for (ApplicationList.ApplicationInfo info : listOfApps.getList()) {
|
||||
if (appName.equals(info.getName())) {
|
||||
for (ApplicationListResponse45.Application info : listOfApps.getList()) {
|
||||
if (appDetail.getName().equals(info.getName()) && appDetail.getOwner().equals(info.getOwner())) {
|
||||
return info.getApplicationId();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error while resolving Application id for name {}: {}", appName, e.getMessage(), e);
|
||||
log.error("Error while resolving Application id for name {}: {}", appDetail.getName(), e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package cz.trask.migration.model.v45;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ApplicationListResponse45 {
|
||||
|
||||
private int count;
|
||||
private Application[] list;
|
||||
private Pagination pagination;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class Application {
|
||||
private String applicationId;
|
||||
private String name;
|
||||
private String owner;
|
||||
private String status;
|
||||
private String groupId;
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class Pagination {
|
||||
private int offset;
|
||||
private int limit;
|
||||
private int total;
|
||||
private String next;
|
||||
private String previous;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user