Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Commit

Permalink
Cluster refactor + Pods + Cluster status
Browse files Browse the repository at this point in the history
  • Loading branch information
remstos committed Jul 7, 2016
1 parent 1c5d976 commit d9fc630
Show file tree
Hide file tree
Showing 33 changed files with 405 additions and 324 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"__DEV__": true,
"alt": true,
"Immutable": true,
"_": true
"_": true,
"Constants": true,
},
"ecmaFeatures": {
"arrowFunctions": true,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
"alt-container": "1.0.2",
"alt-utils": "1.0.0",
"babel-plugin-module-alias": "1.5.0",
"base-64": "^0.1.0",
"immutable": "3.8.1",
"intl": "1.2.4",
"intl-messageformat": "1.3.0",
"intl-relativeformat": "1.3.0",
"lodash": "4.13.1",
"qs": "6.2.0",
"react": "15.2.0",
"react-native": "0.28"
"react-native": "0.28",
"utf8": "^2.1.1"
},
"devDependencies": {
"babel-eslint": "6.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import 'stores/EndpointsStore';
import 'stores/NodesStore';
import 'stores/ClustersStore';
import 'stores/PodsStore';
import 'stores/ServicesStore';
import 'stores/ReplicationsStore';
export default {};
54 changes: 54 additions & 0 deletions src/actions/ClustersActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2015 Skippbox, Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import alt from 'src/alt';
import ClustersApi from 'api/ClustersApi';
import PodsActions from 'actions/PodsActions';
import ServicesActions from 'actions/ServicesActions';
import ReplicationsActions from 'actions/ReplicationsActions';

class ClustersActions {

constructor() {
this.generateActions(
'checkClusterStart',
'checkClusterSuccess',
'addCluster',
'editCluster',
'removeCluster',
);
}

checkClusters() {
return Promise.all(alt.stores.ClustersStore.getClusters().map(cluster => {
return this.checkCluster(cluster);
}));
}

checkCluster(cluster) {
this.checkClusterStart(cluster);
return ClustersApi.checkCluster(cluster).then(up => {
this.checkClusterSuccess({cluster, up});
});
}

fetchClusterEntities(cluster) {
PodsActions.fetchPods.defer(cluster);
ServicesActions.fetchServices.defer(cluster);
ReplicationsActions.fetchReplications.defer(cluster);
}
}

export default alt.createActions(ClustersActions);
29 changes: 0 additions & 29 deletions src/actions/EndpointsActions.js

This file was deleted.

22 changes: 11 additions & 11 deletions src/actions/NodesActions.js → src/actions/PodsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
limitations under the License.
*/
import alt from 'src/alt';
import NodesApi from 'api/NodesApi';
import ClustersApi from 'api/ClustersApi';

class NodesActions {
class PodsActions {

constructor() {
this.generateActions(
'fetchNodesStart',
'fetchNodesSuccess',
'fetchNodesFailure',
'fetchPodsStart',
'fetchPodsSuccess',
'fetchPodsFailure',
);
}

fetchNodes(endpoint) {
this.fetchNodesStart(endpoint);
return NodesApi.fetchNodes(endpoint).then(nodes => {
this.fetchNodesSuccess({endpoint, nodes});
fetchPods(cluster) {
this.fetchPodsStart(cluster);
return ClustersApi.fetchPods(cluster).then(pods => {
this.fetchPodsSuccess({cluster, pods});
})
.catch(() => {
this.fetchNodesFailure(endpoint);
this.fetchPodsFailure(cluster);
});
}
}

export default alt.createActions(NodesActions);
export default alt.createActions(PodsActions);
12 changes: 6 additions & 6 deletions src/actions/ReplicationsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/
import alt from 'src/alt';
import ReplicationsApi from 'api/ReplicationsApi';
import ClustersApi from 'api/ClustersApi';

class ReplicationsActions {

Expand All @@ -26,13 +26,13 @@ class ReplicationsActions {
);
}

fetchReplications(endpoint) {
this.fetchReplicationsStart(endpoint);
return ReplicationsApi.fetchReplications(endpoint).then(replications => {
this.fetchReplicationsSuccess({endpoint, replications});
fetchReplications(cluster) {
this.fetchReplicationsStart(cluster);
return ClustersApi.fetchReplications(cluster).then(replications => {
this.fetchReplicationsSuccess({cluster, replications});
})
.catch(() => {
this.fetchReplicationsFailure(endpoint);
this.fetchReplicationsFailure(cluster);
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/actions/ServicesActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/
import alt from 'src/alt';
import ServicesApi from 'api/ServicesApi';
import ClustersApi from 'api/ClustersApi';

class ServicesActions {

Expand All @@ -26,13 +26,13 @@ class ServicesActions {
);
}

fetchServices(endpoint) {
this.fetchServicesStart(endpoint);
return ServicesApi.fetchServices(endpoint).then(services => {
this.fetchServicesSuccess({endpoint, services});
fetchServices(cluster) {
this.fetchServicesStart(cluster);
return ClustersApi.fetchServices(cluster).then(services => {
this.fetchServicesSuccess({cluster, services});
})
.catch(() => {
this.fetchServicesFailure(endpoint);
this.fetchServicesFailure(cluster);
});
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/api/BaseApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
import StatusCodes from 'utils/StatusCodes';
import Qs from 'qs';
import utf8 from 'utf8';
import base64 from 'base-64';
import { StatusBar, Platform, InteractionManager } from 'react-native';

let REQUESTS_COUNT = 0;
Expand Down Expand Up @@ -43,7 +45,7 @@ class BaseApi {
'Content-Type': 'application/json',
};
if (authentication) {
headers.Authorization = 'Basic ' + btoa(`${authentication.username}:${authentication.password}`);
headers.Authorization = 'Basic ' + base64.encode(utf8.encode(`${authentication.username}:${authentication.password}`));
}

if (dataUrl) {
Expand Down Expand Up @@ -92,7 +94,8 @@ class BaseApi {
return this.apiFetch({method: 'post', url, body});
}

static get(url, dataUrl, authentication) {
static get(url, dataUrl, cluster) {
const authentication = {username: cluster.get('username'), password: cluster.get('password')};
return this.apiFetch({method: 'get', url, dataUrl, authentication});
}

Expand Down
46 changes: 46 additions & 0 deletions src/api/ClustersApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2015 Skippbox, Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import BaseApi from './BaseApi';

class ClustersApi {

static checkCluster(cluster) {
return BaseApi.get(`${cluster.get('url')}/api/v1`, {}, cluster)
.then(() => Promise.resolve(true))
.catch(() => Promise.resolve(false));
}

static fetchPods(cluster) {
return BaseApi.get(`${cluster.get('url')}/api/v1/pods`, {}, cluster).then((response) => {
return response.get('items');
});
}

static fetchReplications(cluster) {
return BaseApi.get(`${cluster.get('url')}/api/v1/replicationcontrollers`, {}, cluster).then((response) => {
return response.get('items');
});
}

static fetchServices(cluster) {
return BaseApi.get(`${cluster.get('url')}/api/v1/services`, {}, cluster).then((response) => {
return response.get('items');
});
}

}

export default ClustersApi;
27 changes: 0 additions & 27 deletions src/api/ReplicationsApi.js

This file was deleted.

27 changes: 0 additions & 27 deletions src/api/ServicesApi.js

This file was deleted.

Loading

0 comments on commit d9fc630

Please sign in to comment.