Skip to content

Instantly share code, notes, and snippets.

@Kjaer
Last active May 1, 2019 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kjaer/03657e15c9810a472df749eef9ce3a46 to your computer and use it in GitHub Desktop.
Save Kjaer/03657e15c9810a472df749eef9ce3a46 to your computer and use it in GitHub Desktop.

ARCH OVERVIEW

COMPONENTS

CENTER
  • has many clusters.
  • passes down the minimum and maximum server count
  • passes down available apps for the cluster

CLUSTER

  • [model]:
    • clusterId,
    • availableAppTypes,
    • servers,
    • apps
    • lastAddedServer // For Deletion.

CLUSTER takes min and max server count and available apps as props.

  • [props]:

    • MIN SERVER COUNT
    • MAX SERVER COUNT
    • appTypes
  • starts with MINIMUM_SERVER_COUNT and deploy them. to do that:

    1. in initializayion (vue:created hook), generate 4 servers using server factory.
    2. put them in the servers array
  • fetches the available apps and assigns them to available apps. to do that:

    1. gets available apps from props
    2. set the fetched available apps to the available apps.
    3. do that inside the created hook.
  • lastAddedServer, servers array and update itself with the changes.
    to do that / (eliminate the iteration)

    1. in created hook, add last item of servers to the last added server
    2. in addServer method, update last added server with newly created server instance
  • serverAvailability iterate over all servers and return the servers that has empty app slots with sorted by their creation date. (iteration for filter/iteration for sort) to do that*

    1. serverAvailability iterate over servers and filtered the free servers(iteration)
    2. during the iteration it keeps half loaded servers and free servers
    3. if free servers exist then sort the servers based on their creation date and return them(iteration) to do that
    4. if free servers not exist but half free servers then sort the servers based on their creation date and return them(iteration) to do that
    5. if none of them exist which means every servers has running two apps, then return empty array.
    6. it only return free servers or half free servers. It does not return them both.
  • add Server[method] to do that:

    • create a server using server factory
    • add it to the servers
    • update the lastAddedServer with same server instance
    • [TBD] add it to the freeServers
  • deploy App[method(params=serverInstance)]

    • create the app using appFactory very much like serverFactory or use the apps comes from parameter.
    • ask server availability for servers to deploy.
    • check the available server count. If all servers are full then cancel the deployment (maybe return false)
    • if any server available,
      • if deployApp not received apps instances as parameters and create the app instance using appFactory

      • then assign the app to the first element of the available servers array

      • if deployApp received apps instances as parameters

      • then iterate over apps it received,

      • inside the iteartion

        • push the app instance to the first element of the available servers
        • check first element's apps array count on the available servers array
        • if it is 2 then shift(remove) it from array
        • for the second and latter iterations
          • if there is no server available which has free slots,
          • then create a message with un-deployed apps
          • then break the iteration.
          • return the message.
  • killServer[method] to do that

    • get the last added server from lastAddedServer
    • extract the apps from the toBeDeleted server
    • send them to deployApp as an array if they are multiple or single app instance if they are only 1
  • killApp[method] OneTab shared tabs Clicking “-” for one of the Available Apps should kill the newest instance of that app in the cluster. to do that

    • iterate over all the apps and filter the selected app type(iteration)
    • reduce the apps arrays based on its creation date (iteration)
    • get the server that has earliest created selected app one from the list and remove it.
servers:[
  {
    id:GUID,
    createdAt: DATE,
    apps:[app_instance, app_instance]
  },
  {
    id:GUID,
    createdAt: DATE,
    apps:[app_instance, app_instance]
  },
  {
    id:GUID,
    createdAt: DATE,
    apps:[app_instance, app_instance]
  }
]
apps: [
  {
    appId:GUID,
    deployedAt:DATE
    serverId:GUID
  },
  {
    appId:GUID,
    deployedAt:DATE
    serverId:GUID
  },
  {
    appId:GUID,
    deployedAt:DATE
    serverId:GUID
  }
]

SERVER

[model]

  • apps

APP

[model]

  • appName
  • appInitial
  • colorSchema

APP_NAV

[model]

  • list

[method]

  • deployApp
  • killApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment