use of org.apache.hadoop.ozone.om.response.upgrade.OMFinalizeUpgradeResponse in project ozone by apache.
the class OMFinalizeUpgradeRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
LOG.trace("Request: {}", getOmRequest());
OMResponse.Builder responseBuilder = OmResponseUtil.getOMResponseBuilder(getOmRequest());
responseBuilder.setCmdType(FinalizeUpgrade);
OMClientResponse response = null;
try {
String username = getOmRequest().getUserInfo().getUserName();
if (ozoneManager.getAclsEnabled() && !ozoneManager.isAdmin(username)) {
throw new OMException("Access denied for user " + username + ". " + "Superuser privilege is required to finalize upgrade.", OMException.ResultCodes.ACCESS_DENIED);
}
FinalizeUpgradeRequest request = getOmRequest().getFinalizeUpgradeRequest();
String upgradeClientID = request.getUpgradeClientId();
StatusAndMessages omStatus = ozoneManager.finalizeUpgrade(upgradeClientID);
UpgradeFinalizationStatus.Status protoStatus = UpgradeFinalizationStatus.Status.valueOf(omStatus.status().name());
UpgradeFinalizationStatus responseStatus = UpgradeFinalizationStatus.newBuilder().setStatus(protoStatus).build();
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
int lV = ozoneManager.getVersionManager().getMetadataLayoutVersion();
omMetadataManager.getMetaTable().addCacheEntry(new CacheKey<>(LAYOUT_VERSION_KEY), new CacheValue<>(Optional.of(String.valueOf(lV)), transactionLogIndex));
FinalizeUpgradeResponse omResponse = FinalizeUpgradeResponse.newBuilder().setStatus(responseStatus).build();
responseBuilder.setFinalizeUpgradeResponse(omResponse);
response = new OMFinalizeUpgradeResponse(responseBuilder.build(), ozoneManager.getVersionManager().getMetadataLayoutVersion());
LOG.trace("Returning response: {}", response);
} catch (IOException e) {
response = new OMFinalizeUpgradeResponse(createErrorOMResponse(responseBuilder, e), -1);
} finally {
addResponseToDoubleBuffer(transactionLogIndex, response, ozoneManagerDoubleBufferHelper);
}
return response;
}
Aggregations