WSO2 API 管理器 - 添加新网关的最佳方式?
WSO2 API Manager - Best way for adding a new gateway?
在我们的环境中,我们有多个网关 运行(出于安全目的,针对每个客户端、环境等)。
这些网关启用了资源缓存,作为默认配置(参见 Configuring caching)
当我们必须添加新网关(例如,新客户)并尝试将已发布的 API 部署到新网关时,我们的问题就出现了。在这种情况下,我们执行以下操作:
- 使用网关分配一台新机器(它们是 Ubuntu AWS 中的 16.04 个实例)。
- 停止 API 管理器(在其他机器上运行)
- 在此 API 管理器中编辑 api-manager.xml,并在环境部分添加新网关
- 启动 API 管理器
- 尝试在新网关中部署 API(我们只在“发布”选项卡的“网关”部分检查新网关)
然后我们得到一个错误,因为它试图重新创建一个以前存在的缓存
TID: [-1234] [] [2018-04-19 16:53:35,698] ERROR {org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle} - org.wso2.carbon.registry.core.exceptions.RegistryException: Execution failed for action : Publish Embedded error : FaultGatewaysException:{"PUBLISHED":{"Prototype":"Error while updating API in the gateway. Error while updating API in the gateway. Cache resourceCache already exists","Production":"Error while updating API in the gateway. Error while updating API in the gateway. Cache resourceCache already exists","Sandbox":"Error while updating API in the gateway. Error while updating API in the gateway. Cache resourceCache already exists"},"UNPUBLISHED":{}} {org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle}
这是我们的网关配置
<APIGateway>
<!-- The environments to which an API will be published -->
<Environments>
<!-- Environments can be of different types. Allowed values are 'hybrid', 'production' and 'sandbox'.
An API deployed on a 'production' type gateway will only support production keys
An API deployed on a 'sandbox' type gateway will only support sandbox keys
An API deployed on a 'hybrid' type gateway will support both production and sandbox keys. -->
<!-- api-console element specifies whether the environment should be listed in API Console or not -->
<Environment type="production" api-console="true">
<Name>Prototype</Name>
<Description>Prototype</Description>
<ServerURL>https://apisandbox.example.com:9446/services/</ServerURL>
<GatewayEndpoint>https://apisandbox.example.com:8246</GatewayEndpoint>
<Username>${admin.username}</Username>
<Password>${admin.password}</Password>
</Environment>
<Environment type="sandbox" api-console="true">
<Name>Sandbox</Name>
<Description>Sandbox</Description>
<ServerURL>https://apisandbox.example.com:9446/services/</ServerURL>
<GatewayEndpoint>https://apisandbox.example.com:8246</GatewayEndpoint>
<Username>${admin.username}</Username>
<Password>${admin.password}</Password>
</Environment>
<Environment type="production" api-console="false">
<Name>Production</Name>
<Description>Production</Description>
<ServerURL>https://apigateway.example.com:9447/services/</ServerURL>
<GatewayEndpoint>https://apigateway.example.com:8247</GatewayEndpoint>
<Username>${admin.username}</Username>
<Password>${admin.password}</Password>
</Environment>
</Environments>
更糟。发生此错误后,自然的操作是降级为 CREATED API,并尝试在所有网关中再次发布。
在这种情况下,我们得到 Exception occurred while trying to invoke service method updateApiFromString
之前 运行 个网关的错误
添加新网关的正确方法是什么?还有,我怎样才能清除损坏的状态?
Add/update Wso2 碳面板(主机名:9443/carbon url)中的 APILifeCycle,代码如下。转到扩展→生命周期和 edit/add APILifeCycle .
<aspect name="APILifeCycle" class="org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle">
<configuration type="literal">
<lifecycle>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
version="1.0"
initialstate="Created">
<state id="Created">
<datamodel>
<data name="checkItems">
<item name="Deprecate old versions after publish the API" forEvent="">
</item>
<item name="Require re-subscription when publish the API" forEvent="">
</item>
</data>
<data name="transitionExecution">
<execution forEvent="Deploy as a Prototype"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Publish"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Publish" target="Published"/>
<transition event="Deploy as a Prototype" target="Prototyped"/>
</state>
<state id="Prototyped">
<datamodel>
<data name="checkItems">
<item name="Deprecate old versions after publish the API" forEvent="">
</item>
<item name="Require re-subscription when publish the API" forEvent="">
</item>
</data>
<data name="transitionExecution">
<execution forEvent="Publish"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Demote to Created"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Publish" target="Published"/>
<transition event="Demote to Created" target="Created"/>
<transition event="Deploy as a Prototype" target="Prototyped"/>
</state>
<state id="Published">
<datamodel>
<data name="transitionExecution">
<execution forEvent="Block"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Deprecate"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Demote to Created"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Deploy as a Prototype"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Block" target="Blocked"/>
<transition event="Deploy as a Prototype" target="Prototyped"/>
<transition event="Demote to Created" target="Created"/>
<transition event="Deprecate" target="Deprecated"/>
<transition event="Publish" target="Published"/>
</state>
<state id="Blocked">
<datamodel>
<data name="transitionExecution">
<execution forEvent="Re-Publish"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Deprecate"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Deprecate" target="Deprecated"/>
<transition event="Re-Publish" target="Published"/>
</state>
<state id="Deprecated">
<datamodel>
<data name="transitionExecution">
<execution forEvent="Retire"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Retire" target="Retired"/>
</state>
<state id="Retired">
</state>
</scxml>
</lifecycle>
</configuration>
</aspect>
关注这个https://docs.wso2.com/display/AM200/Extending+the+API+Life+Cycle
在我们的环境中,我们有多个网关 运行(出于安全目的,针对每个客户端、环境等)。
这些网关启用了资源缓存,作为默认配置(参见 Configuring caching)
当我们必须添加新网关(例如,新客户)并尝试将已发布的 API 部署到新网关时,我们的问题就出现了。在这种情况下,我们执行以下操作:
- 使用网关分配一台新机器(它们是 Ubuntu AWS 中的 16.04 个实例)。
- 停止 API 管理器(在其他机器上运行)
- 在此 API 管理器中编辑 api-manager.xml,并在环境部分添加新网关
- 启动 API 管理器
- 尝试在新网关中部署 API(我们只在“发布”选项卡的“网关”部分检查新网关)
然后我们得到一个错误,因为它试图重新创建一个以前存在的缓存
TID: [-1234] [] [2018-04-19 16:53:35,698] ERROR {org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle} - org.wso2.carbon.registry.core.exceptions.RegistryException: Execution failed for action : Publish Embedded error : FaultGatewaysException:{"PUBLISHED":{"Prototype":"Error while updating API in the gateway. Error while updating API in the gateway. Cache resourceCache already exists","Production":"Error while updating API in the gateway. Error while updating API in the gateway. Cache resourceCache already exists","Sandbox":"Error while updating API in the gateway. Error while updating API in the gateway. Cache resourceCache already exists"},"UNPUBLISHED":{}} {org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle}
这是我们的网关配置
<APIGateway>
<!-- The environments to which an API will be published -->
<Environments>
<!-- Environments can be of different types. Allowed values are 'hybrid', 'production' and 'sandbox'.
An API deployed on a 'production' type gateway will only support production keys
An API deployed on a 'sandbox' type gateway will only support sandbox keys
An API deployed on a 'hybrid' type gateway will support both production and sandbox keys. -->
<!-- api-console element specifies whether the environment should be listed in API Console or not -->
<Environment type="production" api-console="true">
<Name>Prototype</Name>
<Description>Prototype</Description>
<ServerURL>https://apisandbox.example.com:9446/services/</ServerURL>
<GatewayEndpoint>https://apisandbox.example.com:8246</GatewayEndpoint>
<Username>${admin.username}</Username>
<Password>${admin.password}</Password>
</Environment>
<Environment type="sandbox" api-console="true">
<Name>Sandbox</Name>
<Description>Sandbox</Description>
<ServerURL>https://apisandbox.example.com:9446/services/</ServerURL>
<GatewayEndpoint>https://apisandbox.example.com:8246</GatewayEndpoint>
<Username>${admin.username}</Username>
<Password>${admin.password}</Password>
</Environment>
<Environment type="production" api-console="false">
<Name>Production</Name>
<Description>Production</Description>
<ServerURL>https://apigateway.example.com:9447/services/</ServerURL>
<GatewayEndpoint>https://apigateway.example.com:8247</GatewayEndpoint>
<Username>${admin.username}</Username>
<Password>${admin.password}</Password>
</Environment>
</Environments>
更糟。发生此错误后,自然的操作是降级为 CREATED API,并尝试在所有网关中再次发布。
在这种情况下,我们得到 Exception occurred while trying to invoke service method updateApiFromString
之前 运行 个网关的错误
添加新网关的正确方法是什么?还有,我怎样才能清除损坏的状态?
Add/update Wso2 碳面板(主机名:9443/carbon url)中的 APILifeCycle,代码如下。转到扩展→生命周期和 edit/add APILifeCycle .
<aspect name="APILifeCycle" class="org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle">
<configuration type="literal">
<lifecycle>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
version="1.0"
initialstate="Created">
<state id="Created">
<datamodel>
<data name="checkItems">
<item name="Deprecate old versions after publish the API" forEvent="">
</item>
<item name="Require re-subscription when publish the API" forEvent="">
</item>
</data>
<data name="transitionExecution">
<execution forEvent="Deploy as a Prototype"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Publish"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Publish" target="Published"/>
<transition event="Deploy as a Prototype" target="Prototyped"/>
</state>
<state id="Prototyped">
<datamodel>
<data name="checkItems">
<item name="Deprecate old versions after publish the API" forEvent="">
</item>
<item name="Require re-subscription when publish the API" forEvent="">
</item>
</data>
<data name="transitionExecution">
<execution forEvent="Publish"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Demote to Created"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Publish" target="Published"/>
<transition event="Demote to Created" target="Created"/>
<transition event="Deploy as a Prototype" target="Prototyped"/>
</state>
<state id="Published">
<datamodel>
<data name="transitionExecution">
<execution forEvent="Block"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Deprecate"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Demote to Created"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Deploy as a Prototype"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Block" target="Blocked"/>
<transition event="Deploy as a Prototype" target="Prototyped"/>
<transition event="Demote to Created" target="Created"/>
<transition event="Deprecate" target="Deprecated"/>
<transition event="Publish" target="Published"/>
</state>
<state id="Blocked">
<datamodel>
<data name="transitionExecution">
<execution forEvent="Re-Publish"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
<execution forEvent="Deprecate"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Deprecate" target="Deprecated"/>
<transition event="Re-Publish" target="Published"/>
</state>
<state id="Deprecated">
<datamodel>
<data name="transitionExecution">
<execution forEvent="Retire"
class="org.wso2.carbon.apimgt.impl.executors.APIExecutor">
</execution>
</data>
</datamodel>
<transition event="Retire" target="Retired"/>
</state>
<state id="Retired">
</state>
</scxml>
</lifecycle>
</configuration>
</aspect>
关注这个https://docs.wso2.com/display/AM200/Extending+the+API+Life+Cycle