title: WSO2-AM: API calls in store fail after restart
body: <p>We've setup the most recent versions of</p>
  
  <ul>
  <li>API Manager</li>
  <li>Identity Server</li>
  <li>Data Analytics Server</li>
  </ul>
  
  <p>in separate pods on a kubernetes cluster (we've used the existing scripts as a basis for creating the docker images), all sharing relevant MySQL databases hosted in another pod on the same cluster. After a lot of configuring everything works as expected, we can add users/roles, create/publish/invoke APIs and collect analytics on these calls. The last issue we're facing however is, that once an API got published, it's possible to invoke it in the store. The problem appears once the API-manager pod gets restarted (for example by scaling the relevant deployment down/up, not by using the carbon dashboard), once the API-Manager is up and running again after such a (hard) restart, the published APIs are still visible in the store, however, if one tries to make a call to one of the (previously working) endpoints, an 404 message is returned and the API-manager logs the following error:</p>
  
  <blockquote>
    <p>INFO {org.apache.synapse.mediators.builtin.LogMediator} - STATUS =
    Message dispatched to the main sequence. Invalid URL, RESOURCE =
    /"context"/"endpoint being called"</p>
  </blockquote>
  
  <p>where "context" is the context set for a given API while publishing it and "endpoint being called" the REST endpoint of the service which should receive the call. Further, if we try to make a change to the API in the publisher (i.e. re-publish it), there seems to be a 50/50 chance that it works and fixes all issues till the next restart of the pod or an error is thrown when clicking the "Next: Implement" button on the first step, which has been recorded <a href="https://wso2.org/jira/browse/APIMANAGER-3022" rel="nofollow noreferrer">here</a> already (although it says that it has been resolved in a previous version already).</p>
  
  <p>The remaining setup is the following:</p>
  
  <p><strong>Users/Roles</strong></p>
  
  <ul>
  <li><p>User: prod, used for creating and publishing an API in the publisher</p></li>
  <li><p>Roles: prod-role (empty role with no priviledges), internal/creator,
  internal/publisher</p></li>
  <li><p>User: cons, used for invoking an API in the store</p></li>
  <li><p>Roles: cons-role (empty role, no priviledges, just for providing
  access to the API in the store), internal/subscriber</p></li>
  </ul>
  
  <p><strong>Databases</strong></p>
  
  <ul>
  <li><p>WSO2_CARBON_DB referees to a database on the MySQL pod, used only by the API-Manager</p></li>
  <li><p>WSO2REG_DB is supposed to be the shared registry database between the three modules (am, das, is)</p></li>
  </ul>
  
  <p>excerpt from master-datasources.xml from the am:</p>
  
  <pre><code>        &lt;datasource&gt;
               &lt;name&gt;WSO2_CARBON_DB&lt;/name&gt;
               &lt;description&gt;The datasource used by the registry&lt;/description&gt;
               &lt;jndiConfig&gt;
                 &lt;name&gt;jdbc/WSO2CarbonDB&lt;/name&gt;
               &lt;/jndiConfig&gt;
               &lt;definition type="RDBMS"&gt;
                 &lt;configuration&gt;
                   &lt;url&gt;jdbc:mysql://mysql-apimdb:3306/amcarbondb?autoReconnect=true&amp;amp;useSSL=false&lt;/url&gt;
                   &lt;username&gt;wso2carbon&lt;/username&gt;
                   &lt;password&gt;abc&lt;/password&gt;
                   &lt;driverClassName&gt;com.mysql.jdbc.Driver&lt;/driverClassName&gt;
                   &lt;maxActive&gt;50&lt;/maxActive&gt;
                   &lt;maxWait&gt;60000&lt;/maxWait&gt;
                   &lt;testOnBorrow&gt;true&lt;/testOnBorrow&gt;
                   &lt;validationQuery&gt;SELECT 1&lt;/validationQuery&gt;
                   &lt;validationInterval&gt;30000&lt;/validationInterval&gt;
                 &lt;/configuration&gt;
               &lt;/definition&gt;
          &lt;/datasource&gt; 
  
          &lt;datasource&gt;
              &lt;name&gt;WSO2AM_DB&lt;/name&gt;
              &lt;description&gt;The datasource used for API Manager database&lt;/description&gt;
              &lt;jndiConfig&gt;
                  &lt;name&gt;jdbc/WSO2AM_DB&lt;/name&gt;
              &lt;/jndiConfig&gt;
              &lt;definition type="RDBMS"&gt;
                  &lt;configuration&gt;
                      &lt;url&gt;jdbc:mysql://mysql-apimdb:3306/apimgtdb?autoReconnect=true&amp;amp;useSSL=false&lt;/url&gt;
                      &lt;username&gt;wso2carbon&lt;/username&gt;
                      &lt;password&gt;abc&lt;/password&gt;
                      &lt;defaultAutoCommit&gt;false&lt;/defaultAutoCommit&gt;
                      &lt;driverClassName&gt;com.mysql.jdbc.Driver&lt;/driverClassName&gt;
                      &lt;maxActive&gt;50&lt;/maxActive&gt;
                      &lt;maxWait&gt;60000&lt;/maxWait&gt;
                      &lt;testOnBorrow&gt;true&lt;/testOnBorrow&gt;
                      &lt;validationQuery&gt;SELECT 1&lt;/validationQuery&gt;
                      &lt;validationInterval&gt;30000&lt;/validationInterval&gt;
                  &lt;/configuration&gt;
              &lt;/definition&gt;
          &lt;/datasource&gt;
  
          &lt;datasource&gt;
               &lt;name&gt;WSO2UM_DB&lt;/name&gt;
               &lt;description&gt;The datasource used by user manager&lt;/description&gt;
               &lt;jndiConfig&gt;
                 &lt;name&gt;jdbc/WSO2UM_DB&lt;/name&gt;
               &lt;/jndiConfig&gt;
               &lt;definition type="RDBMS"&gt;
                 &lt;configuration&gt;
                   &lt;url&gt;jdbc:mysql://mysql-apimdb:3306/userdb?autoReconnect=true&amp;amp;useSSL=false&lt;/url&gt;
                   &lt;username&gt;wso2carbon&lt;/username&gt;
                   &lt;password&gt;abc&lt;/password&gt;
                   &lt;driverClassName&gt;com.mysql.jdbc.Driver&lt;/driverClassName&gt;
                   &lt;maxActive&gt;50&lt;/maxActive&gt;
                   &lt;maxWait&gt;60000&lt;/maxWait&gt;
                   &lt;testOnBorrow&gt;true&lt;/testOnBorrow&gt;
                   &lt;validationQuery&gt;SELECT 1&lt;/validationQuery&gt;
                   &lt;validationInterval&gt;30000&lt;/validationInterval&gt;
                 &lt;/configuration&gt;
               &lt;/definition&gt;
          &lt;/datasource&gt;
  
          &lt;datasource&gt;
              &lt;name&gt;WSO2REG_DB&lt;/name&gt;
              &lt;description&gt;The datasource used for registry&lt;/description&gt;
              &lt;jndiConfig&gt;
                  &lt;name&gt;jdbc/WSO2REG_DB&lt;/name&gt;
              &lt;/jndiConfig&gt;
              &lt;definition type="RDBMS"&gt;
                  &lt;configuration&gt;
                      &lt;url&gt;jdbc:mysql://mysql-apimdb:3306/regdb?autoReconnect=true&amp;amp;useSSL=false&lt;/url&gt;
                      &lt;username&gt;wso2carbon&lt;/username&gt;
                      &lt;password&gt;abc&lt;/password&gt;
                      &lt;driverClassName&gt;com.mysql.jdbc.Driver&lt;/driverClassName&gt;
                      &lt;maxActive&gt;50&lt;/maxActive&gt;
                      &lt;maxWait&gt;60000&lt;/maxWait&gt;
                      &lt;testOnBorrow&gt;true&lt;/testOnBorrow&gt;
                      &lt;validationQuery&gt;SELECT 1&lt;/validationQuery&gt;
                      &lt;validationInterval&gt;30000&lt;/validationInterval&gt;
                  &lt;/configuration&gt;
              &lt;/definition&gt;
          &lt;/datasource&gt;
  </code></pre>
  
  <p>All of these databases get populated upon usage and are initialized using the DBscripts from the different products for the initial setup. Further, the registry.xml is configured as follows (showing just the changes, the remainder of the file is as it is configured by default): </p>
  
  <pre><code>&lt;currentDBConfig&gt;wso2registry&lt;/currentDBConfig&gt;
  &lt;readOnly&gt;false&lt;/readOnly&gt;
  &lt;enableCache&gt;false&lt;/enableCache&gt;
  &lt;registryRoot&gt;/&lt;/registryRoot&gt;
  
  &lt;dbConfig name="wso2registry"&gt;
      &lt;dataSource&gt;jdbc/WSO2CarbonDB&lt;/dataSource&gt;
  &lt;/dbConfig&gt;
  &lt;dbConfig name="govregistry"&gt;
      &lt;dataSource&gt;jdbc/WSO2REG_DB&lt;/dataSource&gt;
  &lt;/dbConfig&gt;
  
  &lt;remoteInstance url="https://localhost:9943/registry"&gt; 
     &lt;id&gt;gov&lt;/id&gt;
     &lt;dbConfig&gt;govregistry&lt;/dbConfig&gt;
     &lt;cacheId&gt;wso2carbon@jdbc:mysql://mysql-apimdb:3306/regdb&lt;/cacheId&gt;
     &lt;readOnly&gt;false&lt;/readOnly&gt;
     &lt;enableCache&gt;false&lt;/enableCache&gt;
     &lt;registryRoot&gt;/&lt;/registryRoot&gt;
  &lt;/remoteInstance&gt;
  
  &lt;mount path="/_system/governance" overwrite="true"&gt;
         &lt;instanceId&gt;gov&lt;/instanceId&gt;
         &lt;targetPath&gt;/_system/governance&lt;/targetPath&gt;
  &lt;/mount&gt;
  
  &lt;mount path="/_system/config" overwrite="true"&gt;
         &lt;instanceId&gt;gov&lt;/instanceId&gt;
         &lt;targetPath&gt;/_system/config&lt;/targetPath&gt;
  &lt;/mount&gt;
  </code></pre>
  
  <p>In the end it seems to be an issue with some data being lost upon restart as the memory on the am pod is not persistent, since we've moved all databases to a persistent storage on another pod however, this shouldn't be a problem -- unless we missed something. Is there another registry/data source that need to be added/changed? All other default data sources not shown above (STATS, MB_STORE, METRICS) are setup to use the MySQL server as well, so unless there is something else than the data sources provided in the datasource folder, all data should remain on the corresponding MySQL databases.</p>