Skip to content

Commit

Permalink
Removed synchronized blocks added when fixing concurrency issues
Browse files Browse the repository at this point in the history
while deploying APIs during high traffic
  • Loading branch information
thisaltennakoon committed Mar 20, 2024
1 parent 4665c97 commit 2eae438
Showing 1 changed file with 38 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,54 +668,36 @@ public boolean deployAPI(GatewayAPIDTO gatewayAPIDTO) throws AxisFault {
log.debug("Start to undeploy API" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
}

String productionEndpointName = "";
String sandboxEndpointName = "";

if (gatewayAPIDTO.getEndpointEntriesToBeAdd() != null) {
if (gatewayAPIDTO.getEndpointEntriesToBeAdd().length > 0) {
productionEndpointName = gatewayAPIDTO.getEndpointEntriesToBeAdd()[0].getName();
}
if (gatewayAPIDTO.getEndpointEntriesToBeAdd().length > 1) {
sandboxEndpointName = gatewayAPIDTO.getEndpointEntriesToBeAdd()[1].getName();
unDeployAPI(sequenceAdminServiceProxy, restapiAdminServiceProxy, localEntryServiceProxy,
endpointAdminServiceProxy, gatewayAPIDTO, mediationSecurityAdminServiceProxy);
if (log.isDebugEnabled()) {
log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " undeployed");
log.debug("Start to deploy Local entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());

Check warning on line 675 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/service/APIGatewayAdmin.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/service/APIGatewayAdmin.java#L674-L675

Added lines #L674 - L675 were not covered by tests
}
// Add Local Entries
if (gatewayAPIDTO.getLocalEntriesToBeAdd() != null) {
for (GatewayContentDTO localEntry : gatewayAPIDTO.getLocalEntriesToBeAdd()) {
if (localEntryServiceProxy.isEntryExists(localEntry.getName())) {
localEntryServiceProxy.deleteEntry(localEntry.getName());
localEntryServiceProxy.addLocalEntry(localEntry.getContent());

Check warning on line 682 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/service/APIGatewayAdmin.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/service/APIGatewayAdmin.java#L681-L682

Added lines #L681 - L682 were not covered by tests
} else {
localEntryServiceProxy.addLocalEntry(localEntry.getContent());
}
}
}
if (log.isDebugEnabled()) {
log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Local Entries deployed");
log.debug("Start to deploy Endpoint entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());

Check warning on line 690 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/service/APIGatewayAdmin.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/service/APIGatewayAdmin.java#L689-L690

Added lines #L689 - L690 were not covered by tests
}

synchronized (ServiceReferenceHolder.getInstance().getSynapseConfigurationService().getSynapseConfiguration().
acquireLock(productionEndpointName)) {
synchronized (ServiceReferenceHolder.getInstance().getSynapseConfigurationService().getSynapseConfiguration().
acquireLock(sandboxEndpointName)) {
unDeployAPI(sequenceAdminServiceProxy, restapiAdminServiceProxy, localEntryServiceProxy,
endpointAdminServiceProxy, gatewayAPIDTO, mediationSecurityAdminServiceProxy);
if (log.isDebugEnabled()) {
log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " undeployed");
log.debug("Start to deploy Local entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
}
// Add Local Entries
if (gatewayAPIDTO.getLocalEntriesToBeAdd() != null) {
for (GatewayContentDTO localEntry : gatewayAPIDTO.getLocalEntriesToBeAdd()) {
if (localEntryServiceProxy.isEntryExists(localEntry.getName())) {
localEntryServiceProxy.deleteEntry(localEntry.getName());
localEntryServiceProxy.addLocalEntry(localEntry.getContent());
} else {
localEntryServiceProxy.addLocalEntry(localEntry.getContent());
}
}
}
if (log.isDebugEnabled()) {
log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Local Entries deployed");
log.debug("Start to deploy Endpoint entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
}

// Add Endpoints
if (gatewayAPIDTO.getEndpointEntriesToBeAdd() != null) {
for (GatewayContentDTO endpointEntry : gatewayAPIDTO.getEndpointEntriesToBeAdd()) {
if (endpointAdminServiceProxy.isEndpointExist(endpointEntry.getName())) {
endpointAdminServiceProxy.deleteEndpoint(endpointEntry.getName());
endpointAdminServiceProxy.addEndpoint(endpointEntry.getContent());
} else {
endpointAdminServiceProxy.addEndpoint(endpointEntry.getContent());
}
}
// Add Endpoints
if (gatewayAPIDTO.getEndpointEntriesToBeAdd() != null) {
for (GatewayContentDTO endpointEntry : gatewayAPIDTO.getEndpointEntriesToBeAdd()) {
if (endpointAdminServiceProxy.isEndpointExist(endpointEntry.getName())) {
endpointAdminServiceProxy.deleteEndpoint(endpointEntry.getName());
endpointAdminServiceProxy.addEndpoint(endpointEntry.getContent());
} else {
endpointAdminServiceProxy.addEndpoint(endpointEntry.getContent());
}
}
}
Expand Down Expand Up @@ -918,36 +900,18 @@ private void unDeployAPI(SequenceAdminServiceProxy sequenceAdminServiceProxy,

public boolean unDeployAPI(GatewayAPIDTO gatewayAPIDTO) throws AxisFault {

String sandboxEndpointName = "";
String productionEndpointName = "";

if (gatewayAPIDTO.getEndpointEntriesToBeRemove() != null) {
if (gatewayAPIDTO.getEndpointEntriesToBeRemove().length > 0) {
sandboxEndpointName = gatewayAPIDTO.getEndpointEntriesToBeRemove()[0];
}
if (gatewayAPIDTO.getEndpointEntriesToBeRemove().length > 1) {
productionEndpointName = gatewayAPIDTO.getEndpointEntriesToBeRemove()[1];
}
}
SequenceAdminServiceProxy sequenceAdminServiceProxy =
getSequenceAdminServiceClient(gatewayAPIDTO.getTenantDomain());
RESTAPIAdminServiceProxy restapiAdminServiceProxy = getRestapiAdminClient(gatewayAPIDTO.getTenantDomain());
LocalEntryServiceProxy localEntryServiceProxy = new LocalEntryServiceProxy(gatewayAPIDTO.getTenantDomain());
EndpointAdminServiceProxy endpointAdminServiceProxy =
new EndpointAdminServiceProxy(gatewayAPIDTO.getTenantDomain());
MediationSecurityAdminServiceProxy mediationSecurityAdminServiceProxy =
new MediationSecurityAdminServiceProxy(gatewayAPIDTO.getTenantDomain());

synchronized (ServiceReferenceHolder.getInstance().getSynapseConfigurationService().getSynapseConfiguration().
acquireLock(productionEndpointName)) {
synchronized (ServiceReferenceHolder.getInstance().getSynapseConfigurationService().getSynapseConfiguration().
acquireLock(sandboxEndpointName)) {
SequenceAdminServiceProxy sequenceAdminServiceProxy =
getSequenceAdminServiceClient(gatewayAPIDTO.getTenantDomain());
RESTAPIAdminServiceProxy restapiAdminServiceProxy = getRestapiAdminClient(gatewayAPIDTO.getTenantDomain());
LocalEntryServiceProxy localEntryServiceProxy = new LocalEntryServiceProxy(gatewayAPIDTO.getTenantDomain());
EndpointAdminServiceProxy endpointAdminServiceProxy =
new EndpointAdminServiceProxy(gatewayAPIDTO.getTenantDomain());
MediationSecurityAdminServiceProxy mediationSecurityAdminServiceProxy =
new MediationSecurityAdminServiceProxy(gatewayAPIDTO.getTenantDomain());

unDeployAPI(sequenceAdminServiceProxy, restapiAdminServiceProxy, localEntryServiceProxy,
endpointAdminServiceProxy, gatewayAPIDTO, mediationSecurityAdminServiceProxy);
return true;
}
}
unDeployAPI(sequenceAdminServiceProxy, restapiAdminServiceProxy, localEntryServiceProxy,
endpointAdminServiceProxy, gatewayAPIDTO, mediationSecurityAdminServiceProxy);
return true;
}

/**
Expand Down

0 comments on commit 2eae438

Please sign in to comment.