2
votes

In our environment we have several gateway running (for each client, environment and so on, for security purposes).

These gateways have the resource cache enabled, as default configuration (see Configuring caching)

Our problem raises when we have to add a new gateway (e.g., a new customer) and try to deploy an already published API to the new gateway. In this case, we do the following:

  • Allocate a new machine with the gateway (they are Ubuntu 16.04 instances in AWS).
  • Stop the API Manager (runs in other machine)
  • Edit api-manager.xml in this API manager, and add the new gateway in Environments section
  • Start the API Manager
  • Try to deploy the API in the new gateway (we only check the new gateway in the Gateways sections of Publish tab)

Then we get an error, as it tries to recreate an previously existing cache

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}

This is our Gateway configuration

<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>

Even worse. After this error, the natural action is to demote to CREATED the API, and try to publish again in ALL gateways.

In this case, we get Exception occurred while trying to invoke service method updateApiFromStringerror for the previously running gateways

Which is the correct way to add a new gateway? And, how can I clean the corrupted status?

1

1 Answers

0
votes

Add/update APILifeCycle in Wso2 carbon panel(hostname:9443/carbon url) with the following code. Goto extentions→ lifecycles and 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>

Follow this https://docs.wso2.com/display/AM200/Extending+the+API+Life+Cycle