1
0
mirror of https://github.com/yldio/copilot.git synced 2024-09-21 13:53:51 +03:00

Update frontend to use updated schema

This commit is contained in:
JUDIT GRESKOVITS 2017-05-17 19:02:35 +01:00 committed by Sérgio Ramos
parent 4b2e0f53ae
commit 11751129b3
21 changed files with 256 additions and 392 deletions

View File

@ -5,6 +5,7 @@
"dependencies": { "dependencies": {
"apollo": "^0.2.2", "apollo": "^0.2.2",
"babel-plugin-inline-react-svg": "^0.4.0", "babel-plugin-inline-react-svg": "^0.4.0",
"babel-plugin-styled-components": "^1.1.4",
"constant-case": "^2.0.0", "constant-case": "^2.0.0",
"graphql-tag": "^2.0.0", "graphql-tag": "^2.0.0",
"loadash": "^0.0.1", "loadash": "^0.0.1",

View File

@ -23,7 +23,9 @@ module.exports = function(config) {
query: { query: {
babelrc: false, babelrc: false,
presets: [require.resolve('babel-preset-react-app')], presets: [require.resolve('babel-preset-react-app')],
plugins: ["inline-react-svg"], plugins: [["inline-react-svg", {
"ignorePattern": "libre-franklin"
}]],
cacheDirectory: true cacheDirectory: true
} }
}) })

View File

@ -45,7 +45,7 @@ const DeploymentGroupList = ({
return ( return (
<p key={index}> <p key={index}>
<Link <Link
to={`${location.pathname}/${deploymentGroup.pathName}/services`} to={`${location.pathname}/${deploymentGroup.slug}/services`}
> >
{deploymentGroup.name} {deploymentGroup.name}
</Link> </Link>

View File

@ -33,7 +33,7 @@ const InstanceListWithData = graphql(InstancesQuery, {
options(props) { options(props) {
return { return {
variables: { variables: {
deploymentGroupId: props.match.params.deploymentGroup deploymentGroupSlug: props.match.params.deploymentGroup
} }
}; };
}, },

View File

@ -38,23 +38,23 @@ const ConnectedBreadcrumb = connect(
(state, ownProps) => { (state, ownProps) => {
const params = ownProps.match.params; const params = ownProps.match.params;
const deploymentGroupPathName = params.deploymentGroup; const deploymentGroupSlug = params.deploymentGroup;
const servicePathName = params.service; const serviceSlug = params.service;
const apolloData = state.apollo.data; const apolloData = state.apollo.data;
const keys = Object.keys(apolloData); const keys = Object.keys(apolloData);
let deploymentGroup, service; let deploymentGroup, service;
if(keys.length) { if(keys.length) {
// These should be selectors // These should be selectors
if(deploymentGroupPathName) { if(deploymentGroupSlug) {
deploymentGroup = keys.reduce((dg, k) => deploymentGroup = keys.reduce((dg, k) =>
apolloData[k].__typename === 'DeploymentGroup' && apolloData[k].__typename === 'DeploymentGroup' &&
apolloData[k].pathName === deploymentGroupPathName ? apolloData[k].slug === deploymentGroupSlug ?
apolloData[k] : dg, {}); apolloData[k] : dg, {});
if(servicePathName) { if(serviceSlug) {
service = keys.reduce((s, k) => service = keys.reduce((s, k) =>
apolloData[k].__typename === 'Service' && apolloData[k].__typename === 'Service' &&
apolloData[k].pathName === servicePathName ? apolloData[k].slug === serviceSlug ?
apolloData[k] : s, {}); apolloData[k] : s, {});
} }
} }

View File

@ -17,12 +17,12 @@ const ConnectedMenu = connect(
const params = ownProps.match.params; const params = ownProps.match.params;
const matchUrl = ownProps.match.url; const matchUrl = ownProps.match.url;
const deploymentGroupPathName = params.deploymentGroup; const deploymentGroupSlug = params.deploymentGroup;
const servicePathName = params.service; const serviceSlug = params.service;
const sections = servicePathName ? const sections = serviceSlug ?
state.ui.sections.services : state.ui.sections.services :
deploymentGroupPathName ? deploymentGroupSlug ?
state.ui.sections.deploymentGroups : state.ui.sections.deploymentGroups :
null; null;

View File

@ -1,2 +1 @@
export { default as ServiceMetrics } from './metrics';
export { default as SingleMetrics } from './single-metrics';

View File

@ -1,56 +0,0 @@
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import MetricsQuery from '@graphql/Metrics.gql';
class Metrics extends Component {
render() {
const {
instances,
metrics
} = this.props;
return (
<div>
<div>
<h4>Metrics</h4>
<p>{JSON.stringify(metrics)}</p>
</div>
</div>
);
}
}
const MetricsWithData = graphql(MetricsQuery, {
options(props) {
return {
variables: {
deploymentGroupId: props.match.params.deploymentGroup
}
};
},
props: ({ data: { deploymentGroup, loading, error } }) => {
const instances = deploymentGroup && deploymentGroup.services ?
deploymentGroup.services.reduce((instances, service) =>
instances.concat(service.instances), []) : null;
const metrics = instances ? instances.reduce((metrics, instance) =>
metrics.concat(instance.metrics.map((m) =>
Object.assign({}, m, {
instance: {
uuid: instance.uuid,
name: instance.name
}}))), []) : null;
return ({
instances,
metrics,
loading,
error
})
}
})(Metrics)
export default MetricsWithData;

View File

@ -1,35 +0,0 @@
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import SingleMetricsQuery from '@graphql/SingleMetrics.gql';
class SingleMetrics extends Component {
render() {
const {
metrics
} = this.props;
return (
<div>
<div>
<h4>Metrics</h4>
<p>{JSON.stringify(metrics)}</p>
</div>
</div>
);
}
}
const SingleMetricsWithData = graphql(SingleMetricsQuery, {
options: {
pollInterval: 15*1000
},
props: ({ data: { instanceMetric, loading, error } }) => ({
metrics: instanceMetric,
loading,
error
})
})(SingleMetrics)
export default SingleMetricsWithData;

View File

@ -20,7 +20,7 @@ class ServiceList extends Component {
services.map((service, index) => services.map((service, index) =>
<p key={index}> <p key={index}>
<Link <Link
to={`${location.pathname}/${service.id}/instances`} to={`${location.pathname.replace('services-list', 'services')}/${service.slug}/instances`}
> >
{service.name} {service.name}
</Link> </Link>
@ -41,7 +41,7 @@ const ServiceListWithData = graphql(ServicesQuery, {
options(props) { options(props) {
return { return {
variables: { variables: {
deploymentGroupPathName: props.match.params.deploymentGroup deploymentGroupSlug: props.match.params.deploymentGroup
} }
} }
}, },

View File

@ -32,12 +32,6 @@ const ServicesTopology = ({
error error
}) => { }) => {
console.log('push = ', push);
console.log('services = ', services);
console.log('datacenter = ', datacenter);
console.log('loading = ', loading);
console.log('error = ', error);
if(loading) { if(loading) {
return ( return (
<LayoutContainer> <LayoutContainer>
@ -62,9 +56,9 @@ const ServicesTopology = ({
const getService = (s, i) => ({ const getService = (s, i) => ({
index: i, index: i,
...s, ...s,
metrics: s.currentMetrics.map((m) => ({ metrics: [1, 2, 3].map((m) => ({
name: m.name, name: `${m}`,
value: `${m.value}${m.measurement}` value: `${m}`
})), })),
instances: s.instances.length, instances: s.instances.length,
datacenter: datacenter datacenter: datacenter
@ -115,7 +109,7 @@ const ServicesGql = graphql(ServicesQuery, {
options(props) { options(props) {
return { return {
variables: { variables: {
deploymentGroupPathName: props.match.params.deploymentGroup deploymentGroupSlug: props.match.params.deploymentGroup
} }
} }
}, },

View File

@ -2,7 +2,8 @@ query Portal {
portal { portal {
username username
datacenter { datacenter {
id uuid
region
} }
} }
} }

View File

@ -8,11 +8,6 @@ query Instances($deploymentGroupSlug: String!){
...ServiceInfo ...ServiceInfo
parent parent
connections connections
currentMetrics {
name
value
measurement
}
instances { instances {
uuid uuid
} }

View File

@ -14,8 +14,6 @@ import { DeploymentGroupList } from '@containers/deployment-groups';
import { ServiceList, ServicesTopology, ServicesMenu } from '@containers/services'; import { ServiceList, ServicesTopology, ServicesMenu } from '@containers/services';
import { InstanceList } from '@containers/instances'; import { InstanceList } from '@containers/instances';
import { ServiceMetrics, SingleMetrics } from '@containers/service';
const rootRedirect = (p) => ( const rootRedirect = (p) => (
<Redirect to='/deployment-groups' /> <Redirect to='/deployment-groups' />
); );
@ -45,6 +43,7 @@ const Router = (
<Route path='/deployment-groups/:deploymentGroup' exact component={deploymentGroupRedirect} /> <Route path='/deployment-groups/:deploymentGroup' exact component={deploymentGroupRedirect} />
<Route path='/deployment-groups/:deploymentGroup/services' exact component={deploymentGroupRedirect} /> <Route path='/deployment-groups/:deploymentGroup/services' exact component={deploymentGroupRedirect} />
<Route path='/deployment-groups/:deploymentGroup/instances' exact component={InstanceList} />
<Route path={`/deployment-groups/:deploymentGroup/services-list`} exact component={ServicesMenu} /> <Route path={`/deployment-groups/:deploymentGroup/services-list`} exact component={ServicesMenu} />
<Route path='/deployment-groups/:deploymentGroup/services-list' exact component={ServiceList} /> <Route path='/deployment-groups/:deploymentGroup/services-list' exact component={ServiceList} />
@ -53,8 +52,6 @@ const Router = (
<Route path={`/deployment-groups/:deploymentGroup/services-topology`} exact component={ServicesTopology} /> <Route path={`/deployment-groups/:deploymentGroup/services-topology`} exact component={ServicesTopology} />
<Route path='/deployment-groups/:deploymentGroup/services/:service/instances' exact component={InstanceList} /> <Route path='/deployment-groups/:deploymentGroup/services/:service/instances' exact component={InstanceList} />
<Route path='/deployment-groups/:deploymentGroup/services/:service/metrics' exact component={ServiceMetrics} />
<Route path='/deployment-groups/:deploymentGroup/services/:service/single-metrics' exact component={SingleMetrics} />
</div> </div>
</BrowserRouter> </BrowserRouter>

View File

@ -2,19 +2,19 @@ import { createSelector } from 'reselect';
const apollo = (state) => state.apollo; const apollo = (state) => state.apollo;
const deploymentGroupById = (deploymentGroupPathName) => createSelector( const deploymentGroupById = (deploymentGroupSlug) => createSelector(
[apollo], [apollo],
(apollo) => apollo ? Object.keys(apollo).reduce((dg, k) => (apollo) => apollo ? Object.keys(apollo).reduce((dg, k) =>
apollo[k].__typename === 'DeploymentGroup' && apollo[k].__typename === 'DeploymentGroup' &&
apollo[k].pathName === deploymentGroupPathName ? apollo[k].slug === deploymentGroupSlug ?
apollo[k] : dg, {}) : null apollo[k] : dg, {}) : null
); );
const servicesById = (servicePathName) => createSelector( const servicesById = (serviceSlug) => createSelector(
[apollo], [apollo],
(apollo) => apollo ? Object.keys(apollo).reduce((s, k) => (apollo) => apollo ? Object.keys(apollo).reduce((s, k) =>
apollo[k].__typename === 'Service' && apollo[k].__typename === 'Service' &&
apollo[k].pathName === servicePathName ? apollo[k].slug === serviceSlug ?
apollo[k] : s, {}) : null apollo[k] : s, {}) : null
); );

View File

@ -2,48 +2,18 @@ const state = {
ui: { ui: {
sections: { sections: {
deploymentGroups: [{ deploymentGroups: [{
pathname: "feed",
name: "Feed"
}, {
pathname: "services", pathname: "services",
name: "Services" name: "Services"
}, { }, {
pathname: "instances", pathname: "instances",
name: "Instances" name: "Instances"
}, {
pathname: "rollback",
name: "Rollback"
}, { }, {
pathname: "manifest", pathname: "manifest",
name: "Manifest" name: "Manifest"
}, {
pathname: "settings",
name: "Settings"
}], }],
services: [{ services: [{
pathname: "summary",
name: "Summary"
}, {
pathname: "instances", pathname: "instances",
name: "Insatnces" name: "Instances"
}, {
pathname: "metrics",
name: "Metrics"
}, {
pathname: "networks",
name: "Networks"
}, {
pathname: "tags-metadata",
name: "Tags / metadata"
}, {
pathname: "activity-feed",
name: "Activity feed"
}, {
pathname: "manifest",
name: "Manifest"
}, {
pathname: "firewall",
name: "Firewall"
}] }]
} }
} }

View File

@ -1,13 +1,10 @@
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'; import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { ApolloClient, createNetworkInterface } from 'react-apollo'; import { ApolloClient, createNetworkInterface } from 'react-apollo';
import state from './state'; import state from './state';
// import uiReducer from './reducers/ui';
console.log('state = ', state);
export const client = new ApolloClient({ export const client = new ApolloClient({
dataIdFromObject: o => { dataIdFromObject: o => {
const id = o.pathName ? o.pathName : o.id ? o.id : o.uuid ? o.uuid : o.timestamp ? o.timestamp : o.name ? o.name : 'apollo-cache-key-not-defined'; const id = o.slug ? o.slug : o.id ? o.id : o.uuid ? o.uuid : o.timestamp ? o.timestamp : o.name ? o.name : 'apollo-cache-key-not-defined';
return `${o.__typename}:${id}`; return `${o.__typename}:${id}`;
}, },
networkInterface: createNetworkInterface({ networkInterface: createNetworkInterface({

View File

@ -514,6 +514,12 @@ babel-plugin-jest-hoist@^18.0.0:
version "18.0.0" version "18.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-18.0.0.tgz#4150e70ecab560e6e7344adc849498072d34e12a" resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-18.0.0.tgz#4150e70ecab560e6e7344adc849498072d34e12a"
babel-plugin-styled-components@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/babel-plugin-styled-components/-/babel-plugin-styled-components-1.1.4.tgz#b0e6d5bb01059bc7ab9118d3d686f6472ee8e91f"
dependencies:
stylis "2.0.0"
babel-plugin-syntax-async-functions@^6.8.0: babel-plugin-syntax-async-functions@^6.8.0:
version "6.13.0" version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
@ -2002,10 +2008,6 @@ esprima@^2.6.0, esprima@^2.7.1:
version "2.7.3" version "2.7.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
esprima@^3.1.1:
version "3.1.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"
esprima@~3.0.0: esprima@~3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.0.0.tgz#53cf247acda77313e551c3aa2e73342d3fb4f7d9" resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.0.0.tgz#53cf247acda77313e551c3aa2e73342d3fb4f7d9"
@ -3207,14 +3209,7 @@ js-tokens@^3.0.0:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"
js-yaml@^3.4.3, js-yaml@^3.5.1, js-yaml@^3.7.0: js-yaml@^3.4.3, js-yaml@^3.5.1, js-yaml@^3.7.0, js-yaml@~3.7.0:
version "3.8.4"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.4.tgz#520b4564f86573ba96662af85a8cafa7b4b5a6f6"
dependencies:
argparse "^1.0.7"
esprima "^3.1.1"
js-yaml@~3.7.0:
version "3.7.0" version "3.7.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80"
dependencies: dependencies:
@ -5211,6 +5206,10 @@ styled-components@^1.4.6:
prop-types "^15.5.4" prop-types "^15.5.4"
supports-color "^3.1.2" supports-color "^3.1.2"
stylis@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/stylis/-/stylis-2.0.0.tgz#6785a6546bd73478799a67d49d67086953b50ad5"
supports-color@^2.0.0: supports-color@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

View File

@ -2,8 +2,11 @@ import { find, filter } from 'lodash';
import data from './mock-data'; import data from './mock-data';
import { normalMetricData, leakMetricData } from './mock-data/metrics'; import { normalMetricData, leakMetricData } from './mock-data/metrics';
const datacenters = data.datacenters.data; const datacenter = {
const portal = { username: 'juditgreskovits', host: 'dockerhost', datacenter: datacenters[0]}; uuid: 'datacenter-uuid',
region: 'us-east-1'
};
const portal = { username: 'juditgreskovits', host: 'dockerhost', datacenter};
const deploymentGroups = data.projects.data.map(p => { const deploymentGroups = data.projects.data.map(p => {
p.slug = p.id; p.slug = p.id;
return p; return p;
@ -127,10 +130,7 @@ const resolveFunctions = {
}, },
datacenter() { datacenter() {
return { return datacenter;
uuid: 'datacenter-uuid',
region: 'us-east-1'
};
}, },
/*metricTypes() { /*metricTypes() {

View File

@ -0,0 +1,204 @@
scalar Date
scalar Object
type Portal {
username: String!
datacenter: Datacenter!
deploymentGroups: [DeploymentGroup]!
}
type DeploymentGroup {
uuid: ID!
name: String!
slug: String!
services: [Service]!
version: Version!
history: [Version]!
}
type ServiceScale {
uuid: ID!
serviceName: String!
replicas: Int!
}
enum ConvergenceActionType {
NOOP
CREATE
RECREATE
START
}
type ConvergenceAction {
uuid: String!
type: ConvergenceActionType!
service: String! # service name
machines: [String]! # instance machine ids
}
type StateConvergencePlan {
uuid: String!
running: Boolean!
actions: [ConvergenceAction]!
}
type Version {
created: Date! # Either Int or define scalar
manifest: Manifest!
scale: [ServiceScale]!
plan: StateConvergencePlan
}
enum ManifestType {
COMPOSE
MARIPOSA
}
enum ManifestFormat {
JSON
YAML
}
type Manifest {
uuid: String!
created: Date!
type: ManifestType!
format: ManifestFormat!
raw: String!
obj: Object!
}
# immutable
type Service {
uuid: String! # unique id for db row
hash: String! # unique id for version of service
name: String! # human readable name
slug: String!
instances: [Instance]!
# metrics: [MetricType]!
currentMetrics: [CurrentMetric]!
connections: [String!] # list of serviceUuids
parent: ID # parent service uuid
package: Package! # we don't have this in current mock data
}
# for metrics max / min (I guess)
type Package {
uuid: ID!
name: String!
type: String!
memory: Float!
disk: Float!
swap: Float!
lwps: Int!
vcpus: Int!
version: String!
group: String!
}
enum InstanceStatus {
CREATED
RESTARTING
RUNNING
PAUSED
EXITED
DELETED
}
type Instance {
uuid: String!
name: String!
machineId: String!
status: InstanceStatus!
# metrics: [InstanceMetric]!
}
type Datacenter {
uuid: String!
# name: String! # Do we have 'official' human readable names?
region: String!
}
type InstanceMetric {
type: MetricType!
data: [MetricData]!
}
type CurrentMetric {
name: String!
value: Float!
measurement: String!
}
type MetricType {
uuid: String!
name: String!
id: String!
}
type MetricData {
timestamp: Int!
value: Float!
}
# Need to review queries
type Query {
portal: Portal
deploymentGroups: [DeploymentGroup]
deploymentGroup(uuid: String, slug: String): DeploymentGroup
services(deploymentGroupUuid: String, deploymentGroupSlug: String): [Service]
service(uuid: String, slug: String): Service
instances(serviceUuid: String, serviceSlug: String): [Instance]
instance(uuid: String, machineId: String): Instance
metricTypes: [MetricType]
metricData(instanceUuid: String!, metricType: String!, from: Date!, to: Date!): [InstanceMetric]!
package: Package
datacenters: [Datacenter]
# tmp test
instanceMetric: InstanceMetric!
}
# we probably wont use some of these queries or arguments
# but this way we expose the entire db through gql
type Query {
portal: Portal
deploymentGroups(name: String, slug: String): [DeploymentGroup]
deploymentGroup(uuid: ID, name: String, slug: String): DeploymentGroup
serviceScales(serviceName: String, versionUuid: ID): [ServiceScale]
serviceScale(uuid: ID!): ServiceScale
convergenceActions(type: ConvergenceActionType, service: String, versionUuid: ID): [ConvergenceAction]
convergenceAction(uuid: ID!): ConvergenceAction
stateConvergencePlans(running: Boolean, versionUuid: ID): [StateConvergencePlan]
stateConvergencePlan(uuid: ID!): StateConvergencePlan
versions(manifestUuid: ID, deploymentGroupUuid: ID): [Version]
version(uuid: ID, manifestUuid: ID): Version
manifests(type: String, deploymentGroupUuid: ID): [Manifest]
manifest(uuid: ID!): Manifest
services(name: String, slug: String, parentUuid: ID, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Service]
service(uuid: ID, hash: ID): Service
packages(name: String, type: String, memory: Int, disk: Int, swap: Int, lwps: Int, vcpus: Int, version: String, group: String): [Package]
package(uuid: ID!): Package
instances(name: String!, machineId: ID, status: InstanceStatus, serviceUuid: ID, serviceSlug: String, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Instance]
instance(uuid: ID!): Instance
datacenter(uuid: ID, region: String): Datacenter
}
type Mutation {
createDeploymentGroup(name: String!) : DeploymentGroup
updateDeploymentGroup(uuid: ID!, name: String!) : DeploymentGroup
provisionManifest(deploymentGroupUuid: ID!, type: ManifestType!, format: ManifestFormat!, raw: String!) : Version
scale(service: ID!, replicas: Int!) : Version
stopServices(uuids: [ID]!) : [Service]
startServices(uuids: [ID]!) : [Service]
restartServices(uuids: [ID]!) : [Service]
deleteServices(uuids: [ID]!) : [Service]
stopInstances(uuids: [ID]!) : [Instance]
startInstances(uuids: [ID]!) : [Instance]
restartInstances(uuids: [ID]!) : [Instance]
# reprovision() ???
}

View File

@ -1,213 +1,9 @@
import path from 'path';
import { readFileSync } from 'fs';
import { makeExecutableSchema } from 'graphql-tools'; import { makeExecutableSchema } from 'graphql-tools';
import resolvers from './resolvers'; import resolvers from './resolvers';
const schema = ` const schema = readFileSync(path.join(__dirname, 'schema.gql'), 'utf8');
scalar Date
scalar Object
type Portal {
username: String!
datacenter: Datacenter!
deploymentGroups: [DeploymentGroup]!
}
type DeploymentGroup {
uuid: ID!
name: String!
slug: String!
services: [Service]!
version: Version!
history: [Version]!
}
type ServiceScale {
uuid: ID!
serviceName: String!
replicas: Int!
}
enum ConvergenceActionType {
NOOP
CREATE
RECREATE
START
}
type ConvergenceAction {
uuid: String!
type: ConvergenceActionType!
service: String! # service name
machines: [String]! # instance machine ids
}
type StateConvergencePlan {
uuid: String!
running: Boolean!
actions: [ConvergenceAction]!
}
type Version {
created: Date! # Either Int or define scalar
manifest: Manifest!
scale: [ServiceScale]!
plan: StateConvergencePlan
}
enum ManifestType {
COMPOSE
MARIPOSA
}
enum ManifestFormat {
JSON
YAML
}
type Manifest {
uuid: String!
created: Date!
type: ManifestType!
format: ManifestFormat!
raw: String!
obj: Object!
}
# immutable
type Service {
uuid: String! # unique id for db row
hash: String! # unique id for version of service
name: String! # human readable name
slug: String!
instances: [Instance]!
# metrics: [MetricType]!
currentMetrics: [CurrentMetric]!
connections: [String!] # list of serviceUuids
parent: ID # parent service uuid
package: Package! # we don't have this in current mock data
}
# for metrics max / min (I guess)
type Package {
uuid: ID!
name: String!
type: String!
memory: Float!
disk: Float!
swap: Float!
lwps: Int!
vcpus: Int!
version: String!
group: String!
}
enum InstanceStatus {
CREATED
RESTARTING
RUNNING
PAUSED
EXITED
DELETED
}
type Instance {
uuid: String!
name: String!
machineId: String!
status: InstanceStatus!
# metrics: [InstanceMetric]!
}
type Datacenter {
uuid: String!
# name: String! # Do we have 'official' human readable names?
region: String!
}
type InstanceMetric {
type: MetricType!
data: [MetricData]!
}
type CurrentMetric {
name: String!
value: Float!
measurement: String!
}
type MetricType {
uuid: String!
name: String!
id: String!
}
type MetricData {
timestamp: Int!
value: Float!
}
# Need to review queries
type Query {
portal: Portal
deploymentGroups: [DeploymentGroup]
deploymentGroup(uuid: String, slug: String): DeploymentGroup
services(deploymentGroupUuid: String, deploymentGroupSlug: String): [Service]
service(uuid: String, slug: String): Service
instances(serviceUuid: String, serviceSlug: String): [Instance]
instance(uuid: String, machineId: String): Instance
metricTypes: [MetricType]
metricData(instanceUuid: String!, metricType: String!, from: Date!, to: Date!): [InstanceMetric]!
package: Package
datacenters: [Datacenter]
# tmp test
instanceMetric: InstanceMetric!
}
# we probably wont use some of these queries or arguments
# but this way we expose the entire db through gql
type Query {
portal: Portal
deploymentGroups(name: String, slug: String): [DeploymentGroup]
deploymentGroup(uuid: ID, name: String, slug: String): DeploymentGroup
serviceScales(serviceName: String, versionUuid: ID): [ServiceScale]
serviceScale(uuid: ID!): ServiceScale
convergenceActions(type: ConvergenceActionType, service: String, versionUuid: ID): [ConvergenceAction]
convergenceAction(uuid: ID!): ConvergenceAction
stateConvergencePlans(running: Boolean, versionUuid: ID): [StateConvergencePlan]
stateConvergencePlan(uuid: ID!): StateConvergencePlan
versions(manifestUuid: ID, deploymentGroupUuid: ID): [Version]
version(uuid: ID, manifestUuid: ID): Version
manifests(type: String, deploymentGroupUuid: ID): [Manifest]
manifest(uuid: ID!): Manifest
services(name: String, slug: String, parentUuid: ID, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Service]
service(uuid: ID, hash: ID): Service
packages(name: String, type: String, memory: Int, disk: Int, swap: Int, lwps: Int, vcpus: Int, version: String, group: String): [Package]
package(uuid: ID!): Package
instances(name: String!, machineId: ID, status: InstanceStatus, serviceUuid: ID, serviceSlug: String, deploymentGroupUuid: ID, deploymentGroupSlug: String): [Instance]
instance(uuid: ID!): Instance
datacenter(uuid: ID, region: String): Datacenter
}
type Mutation {
createDeploymentGroup(name: String!) : DeploymentGroup
updateDeploymentGroup(uuid: ID!, name: String!) : DeploymentGroup
provisionManifest(deploymentGroupUuid: ID!, type: ManifestType!, format: ManifestFormat!, raw: String!) : Version
scale(service: ID!, replicas: Int!) : Version
stopServices(uuids: [ID]!) : [Service]
startServices(uuids: [ID]!) : [Service]
restartServices(uuids: [ID]!) : [Service]
deleteServices(uuids: [ID]!) : [Service]
stopInstances(uuids: [ID]!) : [Instance]
startInstances(uuids: [ID]!) : [Instance]
restartInstances(uuids: [ID]!) : [Instance]
# reprovision() ???
}
`;
export default makeExecutableSchema({ export default makeExecutableSchema({
typeDefs: schema, typeDefs: schema,