【问题标题】:WSO2 API Manager - Best way for adding a new gateway?WSO2 API Manager - 添加新网关的最佳方式?
【发布时间】:2018-04-19 15:27:04
【问题描述】:

在我们的环境中,我们运行了多个网关(出于安全目的,针对每个客户端、环境等)。

这些网关启用了资源缓存,作为默认配置(请参阅Configuring caching

当我们必须添加新网关(例如,新客户)并尝试将已发布的 API 部署到新网关时,就会出现问题。在这种情况下,我们执行以下操作:

  • 使用网关分配一台新机器(它们是 AWS 中的 Ubuntu 16.04 实例)。
  • 停止 API 管理器(在其他机器上运行)
  • 在此 API 管理器中编辑 api-manager.xml,并在 Environments 部分添加新网关
  • 启动 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 updateApiFromStringerror

添加新网关的正确方法是什么?还有,如何清除损坏的状态?

【问题讨论】:

    标签: caching wso2 wso2-am gateway


    【解决方案1】:

    使用以下代码在 Wso2 碳面板(主机名:9443/碳 url)中添加/更新 APILifeCycle。转到扩展→生命周期并编辑/添加 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多