Skip to content

Commit

Permalink
Fixing APIMANAGER-4217 changes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
tharikaGitHub committed Dec 8, 2015
1 parent b4598b3 commit e469004
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1996,12 +1996,16 @@ public SubscriptionResponse addSubscription(APIIdentifier identifier, String use
if (APIUtil.isAPIGatewayKeyCacheEnabled()) {
invalidateCachedKeys(applicationId);
}

SubscribedAPI addedSubscription = getSubscriptionById(subscriptionId);

if (log.isDebugEnabled()) {
String logMessage = "API Name: " + identifier.getApiName() + ", API Version " + identifier.getVersion()
+ " subscribe by " + userId + " for app " + apiMgtDAO.getApplicationNameFromId(applicationId);
+ ", Subscription Status: " + addedSubscription.getSubStatus() + " subscribe by " + userId
+ " for app " + apiMgtDAO.getApplicationNameFromId(applicationId);
log.debug(logMessage);
}
SubscribedAPI addedSubscription = getSubscriptionById(subscriptionId);

return new SubscriptionResponse(addedSubscription.getSubStatus(), addedSubscription.getUUID(),
workflowResponse);
} else {
Expand Down Expand Up @@ -2215,6 +2219,11 @@ public int addApplication(Application application, String userId)
PrivilegedCarbonContext.endTenantFlow();
}
}

if (log.isDebugEnabled()) {
log.debug("Application Name: " + application.getName() +" added successfully.");
}

return applicationId;
}

Expand Down Expand Up @@ -2243,6 +2252,9 @@ public void updateApplication(Application application) throws APIManagementExcep
}

apiMgtDAO.updateApplication(application);
if (log.isDebugEnabled()) {
log.debug("Successfully updated the Application: " + application.getId() +" in the database.");
}

APIKey[] apiKeys = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,12 @@ public void removeTier(Tier tier) throws APIManagementException {
public void addAPI(API api) throws APIManagementException {
try {
createAPI(api);

if (log.isDebugEnabled()) {
log.debug("API details successfully added to the registry. API Name: " + api.getId().getApiName()
+ ", API Version : " + api.getId().getVersion() + ", API context : " + api.getContext());
}

int tenantId;
String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(api.getId().getProviderName()));
try {
Expand All @@ -575,6 +581,13 @@ public void addAPI(API api) throws APIManagementException {
+api.getId().getApiName(),e);
}
apiMgtDAO.addAPI(api,tenantId);

if (log.isDebugEnabled()) {
log.debug("API details successfully added to the API Manager Database. API Name: " + api.getId()
.getApiName() + ", API Version : " + api.getId().getVersion() + ", API context : " + api
.getContext());
}

if (APIUtil.isAPIManagementEnabled()) {
Cache contextCache = APIUtil.getAPIContextCache();
Boolean apiContext = null;
Expand Down Expand Up @@ -739,6 +752,9 @@ public void updateAPI(API api) throws APIManagementException, FaultGatewaysExcep
+api.getId().getApiName(),e);
}
apiMgtDAO.updateAPI(api,tenantId);
if (log.isDebugEnabled()) {
log.debug("Successfully updated the API: " + api.getId() + " in the database");
}

APIManagerConfiguration config = ServiceReferenceHolder.getInstance().
getAPIManagerConfigurationService().getAPIManagerConfiguration();
Expand Down Expand Up @@ -1046,6 +1062,12 @@ public boolean updateAPIStatus(APIIdentifier identifier, String status, boolean
}
}
success = true;
if (log.isDebugEnabled()) {
log.debug("API status successfully updated to: " + newStatus + " in API Name: " + api.getId()
.getApiName() + ", API Version : " + api.getId().getVersion() + ", API context : " + api
.getContext());
}

} else {
handleException("Couldn't find an API with the name-" + name + "version-" + version);
}
Expand Down Expand Up @@ -1741,9 +1763,14 @@ public void createNewAPIVersion(API api, String newVersion) throws DuplicateAPIE
+api.getId().getApiName(),e);
}

apiMgtDAO.addAPI(newAPI,tenantId);
apiMgtDAO.addAPI(newAPI, tenantId);
registry.commitTransaction();

if(log.isDebugEnabled()) {
String logMessage = "Successfully created new version : " + newVersion + " of : " + api.getId().getApiName();
log.debug(logMessage);
}

} catch (ParseException e) {
String msg = "Couldn't Create json Object from Swagger object for version" + newVersion + " of : " +
api.getId().getApiName();
Expand Down Expand Up @@ -2069,11 +2096,14 @@ private void createAPI(API api) throws APIManagementException {
if (visibleRolesList != null) {
visibleRoles = visibleRolesList.split(",");
}
APIUtil.setResourcePermissions(api.getId().getProviderName(), api.getVisibility(), visibleRoles, artifactPath);
APIUtil.setResourcePermissions(api.getId().getProviderName(), api.getVisibility(), visibleRoles,
artifactPath);
registry.commitTransaction();
if(log.isDebugEnabled()){
String logMessage = "API Name: " + api.getId().getApiName() + ", API Version "+api.getId().getVersion()+" created";
log.debug(logMessage);
if (log.isDebugEnabled()) {
String logMessage =
"API Name: " + api.getId().getApiName() + ", API Version " + api.getId().getVersion()
+ " created";
log.debug(logMessage);
}
} catch (Exception e) {
try {
Expand Down Expand Up @@ -2312,6 +2342,13 @@ public void deleteAPI(APIIdentifier identifier) throws APIManagementException {

apiMgtDAO.deleteAPI(identifier);

if (log.isDebugEnabled()) {
String logMessage =
"API Name: " + api.getId().getApiName() + ", API Version " + api.getId().getVersion()
+ " successfully removed from the database.";
log.debug(logMessage);
}

/*remove empty directories*/
String apiCollectionPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR +
identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName();
Expand Down Expand Up @@ -3088,6 +3125,13 @@ public boolean changeLifeCycleStatus(APIIdentifier apiIdentifier, String action)
}

}

if (log.isDebugEnabled()) {
String logMessage =
"API Status changed successfully. API Name: " + apiIdentifier.getApiName() + ", API Version " +
apiIdentifier.getVersion() + ", New Status : " + targetStatus;
log.debug(logMessage);
}
return true;
} catch (GovernanceException e) {
handleException("Failed to change the life cycle status : " + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5506,15 +5506,28 @@ public void deleteApplication(Application application, Connection connection) th
deleteMappingQuery.execute();
}

if (log.isDebugEnabled()) {
log.debug("Subscription Key mapping details are deleted successfully for Application - " + application
.getName());
}

deleteRegistrationQuery = connection.prepareStatement(deleteRegistrationEntry);
deleteRegistrationQuery.setInt(1, application.getId());
deleteRegistrationQuery.execute();

if (log.isDebugEnabled()) {
log.debug("Application Registration details are deleted successfully for Application - " + application
.getName());
}

deleteSubscription = connection.prepareStatement(deleteSubscriptionsQuery);
deleteSubscription.setInt(1, application.getId());
deleteSubscription.execute();

if (log.isDebugEnabled()) {
log.debug("Subscription details are deleted successfully for Application - " + application.getName());
}

prepStmtGetConsumerKey = connection.prepareStatement(getConsumerKeyQuery);
prepStmtGetConsumerKey.setInt(1, application.getId());
rs = prepStmtGetConsumerKey.executeQuery();
Expand Down Expand Up @@ -5545,11 +5558,19 @@ public void deleteApplication(Application application, Connection connection) th
deleteAppKey.setInt(1, application.getId());
deleteAppKey.execute();

if (log.isDebugEnabled()) {
log.debug("Application Key Mapping details are deleted successfully for Application - " + application
.getName());
}

deleteApp = connection.prepareStatement(deleteApplicationQuery);
deleteApp.setInt(1, application.getId());
deleteApp.execute();

if (log.isDebugEnabled()) {
log.debug("Application " + application.getName() + " is deleted successfully.");
}

for (String consumerKey : consumerKeys){
//delete on oAuthorization server.
KeyManagerHolder.getKeyManagerInstance().deleteApplication(consumerKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,25 @@ public boolean execute(RequestContext context, String currentState, String targe
//executed = apiProvider.updateAPIStatus(api.getId(), targetState, true, deprecateOldVersions, makeKeysForwardCompatible);

//push the state change to gateway
Map<String, String> failedGateways = apiProvider.propergateAPIStatusChangeToGateways(api.getId(), newStatus);
Map<String, String> failedGateways = apiProvider.propergateAPIStatusChangeToGateways(api.getId(), newStatus);

if (log.isDebugEnabled()) {
String logMessage = "Publish changed status to the Gateway. API Name: " + api.getId().getApiName()
+ ", API Version " + api.getId().getVersion() + ", API Context: " + api.getContext()
+ ", New Status : " + newStatus;
log.debug(logMessage);
}

//update api related information for state change
executed = apiProvider.updateAPIforStateChange(api.getId(), newStatus, failedGateways);

if (log.isDebugEnabled()) {
String logMessage =
"API related information successfully updated. API Name: " + api.getId().getApiName()
+ ", API Version " + api.getId().getVersion() + ", API Context: " + api.getContext()
+ ", New Status : " + newStatus;
log.debug(logMessage);
}

if ((oldStatus.equals(APIStatus.CREATED) || oldStatus.equals(APIStatus.PROTOTYPED))
&& newStatus.equals(APIStatus.PUBLISHED)) {
Expand Down

0 comments on commit e469004

Please sign in to comment.