Skip to content

Commit feddeae

Browse files
committed
Update holder implementation to fix gw config update in two cp issue
1 parent 65b1ddb commit feddeae

File tree

3 files changed

+24
-50
lines changed

3 files changed

+24
-50
lines changed

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/deployer/GatewayConfigurationService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ void addGatewayConfiguration(String organization, String name, String type,
2929
void updateGatewayConfiguration(String organization, String name, String type,
3030
Environment environment) throws APIManagementException;
3131

32-
void removeGatewayConfiguration(String tenantDomain, String name) throws APIManagementException;
32+
void removeGatewayConfiguration(String organization, String name) throws APIManagementException;
3333
}

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/deployer/GatewayConfigurationServiceImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public void updateGatewayConfiguration(String organization, String name, String
4242
}
4343

4444
@Override
45-
public void removeGatewayConfiguration(String tenantDomain, String name) throws APIManagementException {
46-
String internKey = this.getClass().getName().concat(tenantDomain).concat(name);
45+
public void removeGatewayConfiguration(String organization, String name) throws APIManagementException {
46+
String internKey = this.getClass().getName().concat(organization).concat(name);
4747
synchronized (internKey.intern()) {
48-
GatewayHolder.removeGatewayConfiguration(tenantDomain, name);
48+
GatewayHolder.removeGatewayConfiguration(organization, name);
4949
}
5050
}
5151
}

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/factory/GatewayHolder.java

+20-46
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@
2626
import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
2727
import org.wso2.carbon.apimgt.api.model.GatewayConfiguration;
2828
import org.wso2.carbon.apimgt.api.model.GatewayDeployer;
29-
import org.wso2.carbon.apimgt.api.model.KeyManager;
3029
import org.wso2.carbon.apimgt.impl.APIConstants;
3130
import org.wso2.carbon.apimgt.impl.dto.GatewayDto;
32-
import org.wso2.carbon.apimgt.impl.dto.KeyManagerDto;
3331
import org.wso2.carbon.apimgt.impl.dto.OrganizationGatewayDto;
34-
import org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto;
3532
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
36-
import org.wso2.carbon.apimgt.impl.loader.KeyManagerConfigurationDataRetriever;
3733
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
3834

3935
import java.lang.reflect.InvocationTargetException;
@@ -86,60 +82,38 @@ public static void updateGatewayConfiguration(String organization, String name,
8682
addGatewayConfiguration(organization, name, type, environment);
8783
}
8884

89-
public static void removeGatewayConfiguration(String tenantDomain, String name) {
85+
public static void removeGatewayConfiguration(String organization, String name) {
9086

91-
OrganizationGatewayDto organizationGatewayDto = getTenantGatewayDtoFromMap(tenantDomain);
87+
OrganizationGatewayDto organizationGatewayDto = getTenantGatewayDtoFromMap(organization);
9288
if (organizationGatewayDto != null) {
9389
organizationGatewayDto.removeGatewayDtoByName(name);
9490
}
9591
}
9692

97-
public static GatewayDeployer getTenantGatewayInstance(String tenantDomain, String gatewayName) {
98-
99-
OrganizationGatewayDto organizationGatewayDto = getTenantGatewayDto(tenantDomain);
100-
if (organizationGatewayDto != null) {
101-
GatewayDto gatewayDto = organizationGatewayDto.getGatewayByName(gatewayName);
102-
if (gatewayDto == null) {
103-
return null;
104-
}
105-
return gatewayDto.getGatewayDeployer();
106-
}
107-
return null;
108-
}
109-
110-
private static OrganizationGatewayDto getTenantGatewayDto(String tenantDomain) {
111-
112-
OrganizationGatewayDto organizationGatewayDto = getTenantGatewayDtoFromMap(tenantDomain);
113-
if (organizationGatewayDto == null) {
93+
public static GatewayDeployer getTenantGatewayInstance(String organization, String gatewayName) {
94+
/* At the moment we fetch the environment from DB each time */
95+
synchronized (gatewayName.intern()) {
11496
try {
115-
Map<String, Environment> environmentMap = APIUtil.getEnvironments(tenantDomain);
116-
OrganizationGatewayDto newOrganizationGatewayDto = new OrganizationGatewayDto();
117-
for (Map.Entry<String, Environment> entry : environmentMap.entrySet()) {
118-
Environment environment = entry.getValue();
119-
if (environment.getProvider().equals(APIConstants.EXTERNAL_GATEWAY_VENDOR)) {
120-
GatewayDto gatewayDto = new GatewayDto();
121-
gatewayDto.setName(entry.getKey());
122-
GatewayAgentConfiguration gatewayAgentConfiguration = ServiceReferenceHolder.getInstance().
123-
getExternalGatewayConnectorConfiguration(entry.getValue().getGatewayType());
124-
GatewayDeployer deployer = (GatewayDeployer) Class.forName(gatewayAgentConfiguration.getImplementation())
125-
.getDeclaredConstructor().newInstance();
126-
deployer.init(entry.getValue());
127-
gatewayDto.setGatewayDeployer(deployer);
128-
newOrganizationGatewayDto.putGatewayDto(gatewayDto);
129-
}
97+
Map<String, Environment> environmentMap = APIUtil.getEnvironments(organization);
98+
Environment environment = environmentMap.get(gatewayName);
99+
if (environment != null) {
100+
GatewayAgentConfiguration gatewayAgentConfiguration = ServiceReferenceHolder.getInstance().
101+
getExternalGatewayConnectorConfiguration(environment.getGatewayType());
102+
GatewayDeployer deployer = (GatewayDeployer) Class.forName(gatewayAgentConfiguration.getImplementation())
103+
.getDeclaredConstructor().newInstance();
104+
deployer.init(environment);
105+
return deployer;
130106
}
131-
organizationWiseMap.put(tenantDomain, newOrganizationGatewayDto);
132-
return newOrganizationGatewayDto;
133-
} catch (APIManagementException | ClassNotFoundException | IllegalAccessException | InstantiationException
134-
| NoSuchMethodException | InvocationTargetException e) {
135-
log.error("Error while loading environments for tenant " + tenantDomain, e);
107+
} catch (APIManagementException | ClassNotFoundException | NoSuchMethodException |
108+
InstantiationException | IllegalAccessException | InvocationTargetException e) {
109+
log.error("Error while loading environments for tenant " + organization, e);
136110
return null;
137111
}
138112
}
139-
return organizationGatewayDto;
113+
return null;
140114
}
141115

142-
private static OrganizationGatewayDto getTenantGatewayDtoFromMap(String tenantDomain) {
143-
return organizationWiseMap.get(tenantDomain);
116+
private static OrganizationGatewayDto getTenantGatewayDtoFromMap(String organization) {
117+
return organizationWiseMap.get(organization);
144118
}
145119
}

0 commit comments

Comments
 (0)