|
26 | 26 | import org.wso2.carbon.apimgt.api.model.GatewayAgentConfiguration;
|
27 | 27 | import org.wso2.carbon.apimgt.api.model.GatewayConfiguration;
|
28 | 28 | import org.wso2.carbon.apimgt.api.model.GatewayDeployer;
|
29 |
| -import org.wso2.carbon.apimgt.api.model.KeyManager; |
30 | 29 | import org.wso2.carbon.apimgt.impl.APIConstants;
|
31 | 30 | import org.wso2.carbon.apimgt.impl.dto.GatewayDto;
|
32 |
| -import org.wso2.carbon.apimgt.impl.dto.KeyManagerDto; |
33 | 31 | import org.wso2.carbon.apimgt.impl.dto.OrganizationGatewayDto;
|
34 |
| -import org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto; |
35 | 32 | import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
|
36 |
| -import org.wso2.carbon.apimgt.impl.loader.KeyManagerConfigurationDataRetriever; |
37 | 33 | import org.wso2.carbon.apimgt.impl.utils.APIUtil;
|
38 | 34 |
|
39 | 35 | import java.lang.reflect.InvocationTargetException;
|
@@ -86,60 +82,38 @@ public static void updateGatewayConfiguration(String organization, String name,
|
86 | 82 | addGatewayConfiguration(organization, name, type, environment);
|
87 | 83 | }
|
88 | 84 |
|
89 |
| - public static void removeGatewayConfiguration(String tenantDomain, String name) { |
| 85 | + public static void removeGatewayConfiguration(String organization, String name) { |
90 | 86 |
|
91 |
| - OrganizationGatewayDto organizationGatewayDto = getTenantGatewayDtoFromMap(tenantDomain); |
| 87 | + OrganizationGatewayDto organizationGatewayDto = getTenantGatewayDtoFromMap(organization); |
92 | 88 | if (organizationGatewayDto != null) {
|
93 | 89 | organizationGatewayDto.removeGatewayDtoByName(name);
|
94 | 90 | }
|
95 | 91 | }
|
96 | 92 |
|
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()) { |
114 | 96 | 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; |
130 | 106 | }
|
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); |
136 | 110 | return null;
|
137 | 111 | }
|
138 | 112 | }
|
139 |
| - return organizationGatewayDto; |
| 113 | + return null; |
140 | 114 | }
|
141 | 115 |
|
142 |
| - private static OrganizationGatewayDto getTenantGatewayDtoFromMap(String tenantDomain) { |
143 |
| - return organizationWiseMap.get(tenantDomain); |
| 116 | + private static OrganizationGatewayDto getTenantGatewayDtoFromMap(String organization) { |
| 117 | + return organizationWiseMap.get(organization); |
144 | 118 | }
|
145 | 119 | }
|
0 commit comments