Skip to content

Commit a1de743

Browse files
committed
"fix docker v1 promise not resolving"
1 parent 1dd79e4 commit a1de743

File tree

19 files changed

+179
-83
lines changed

19 files changed

+179
-83
lines changed

app/components/TransferColumns.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const TransferColumns = React.memo(() => {
121121
const createSelectedMetricsList = () => {
122122
const temp: any[] = [];
123123
const categorySet = new Set();
124+
console.log('Inside TransferColumns.txs line 124 targetKeys: ', targetKeys)
124125
for (let i = 0; i < targetKeys.length; i++) {
125126
const str: string = targetKeys[i];
126127
const strArr: string[] = str.split(' | ');
@@ -191,6 +192,7 @@ const TransferColumns = React.memo(() => {
191192
color="primary"
192193
>
193194
Get Charts
195+
I'm in TransferColumns.txs line 194!
194196
</Button>
195197
</div>
196198
<div id="transferTest">

app/containers/GraphsContainer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ const GraphsContainer: React.FC = React.memo(props => {
4747

4848
useEffect(() => {
4949
const serviceArray = service.split(' ');
50-
// You would think you should add "kubernetesmetrics" into the below for consistency's sake but it makes it
51-
// not work correctly, so it has been omitted
50+
// You would think you should add "kubernetesmetrics" into the below for consistency's sake but it makes it not work correctly, so it has been omitted
5251
const healthServiceArray = serviceArray.filter((value: string) => value !== 'kafkametrics' && value !== 'kubernetesmetrics');
5352
if (live) {
5453
setIntervalID(
@@ -87,6 +86,7 @@ const GraphsContainer: React.FC = React.memo(props => {
8786
};
8887
}, [service, live]);
8988

89+
//random variable to hold the light or dark mode of the display?..ok....sure
9090
const currentMode = mode === 'light' ? lightAndDark.lightModeText : lightAndDark.darkModeText;
9191

9292
const routing = (route: string) => {
@@ -156,9 +156,10 @@ const GraphsContainer: React.FC = React.memo(props => {
156156
onClick={() => routing('all')}
157157
key="0"
158158
>
159-
Metrics Query
159+
Metrics Query onclick is not coming thru
160160
</button>
161161
{HealthAndEventButtons}
162+
<div font-color='white'>Here I am! in GraphsContainer.tsx!</div>
162163
{dockerData.containername && (
163164
<button
164165
id="docker-button"
@@ -208,6 +209,7 @@ const GraphsContainer: React.FC = React.memo(props => {
208209
{chart === 'all' && (
209210
<div className="transferColumns">
210211
<h2 style={currentMode}>Search Your Metrics to Display</h2>
212+
<div>THIS is LINE 212 in graphsContainer.tsx!!</div>
211213
<TransferColumns />
212214
</div>
213215
)}

app/context/ApplicationContext.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
2525
const [savedMetrics, setSavedMetrics] = useState({});
2626
const [appIndex, setAppIndex] = useState<number>(0);
2727
const [intervalID, setIntervalID] = useState<NodeJS.Timeout | null>(null);
28-
28+
2929

3030
/**
3131
* @function fetchServicesNames - a function that will take an application name and update the state of `serviceData` based on backend response
@@ -34,7 +34,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
3434
* 3. Upon `servicesResponse`, parse the received JSON data and assign it to `servicesData`
3535
* 4. Remove the listener for `servicesResponse`
3636
* @param application - application name
37-
*/
37+
*/
3838
// v10: Invoked by connectToDB, passing in app (card title)
3939
const fetchServicesNames = useCallback((application: string) => {
4040
// console.log('Hi, inside ApplicationConext - fetchServicesNames callback. Sending servicesRequest to ipcMain.');
@@ -43,7 +43,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
4343
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
4444
let result: any;
4545
result = JSON.parse(data);
46-
// console.log('result from ipcrenderer services response is: ', result);
46+
console.log('result from ipcrenderer services response is: ', result);
4747
// console.log('Calling setServicesData passing in above result. Current servicesData is the following: ', servicesData);
4848
setServicesData(result);
4949
// console.log('Leaving fetchedServicesNames function.');
@@ -55,7 +55,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
5555
/**
5656
* @function connectToTB - invoked in Services Modal when Service Modal component is first rendered or when useEffect invoked.
5757
* creates an event emitter that connects to the user provided URI for the service (should be the database URI...)
58-
* v10 notes: seems to only be set up for local instances, not when a cloud based service is clicked, causes an issue since a user provided
58+
* v10 notes: seems to only be set up for local instances, not when a cloud based service is clicked, causes an issue since a user provided
5959
* database should not exist...
6060
* @params application - is the name of the card taht was clicked on
6161
*/
@@ -74,7 +74,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
7474

7575
/**
7676
* @function getSavedMetrics - a function that will wait for backend `savedMetricsResponse` to update metrics using `setSavedMetrics`
77-
* Trying to find what the data type needs to be.
77+
* Trying to find what the data type needs to be.
7878
*/
7979
const getSavedMetrics = useCallback(() => {
8080
ipcRenderer.send('savedMetricsRequest');
@@ -100,7 +100,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
100100
getSavedMetrics,
101101
setSavedMetrics,
102102
savedMetrics,
103-
appIndex,
103+
appIndex,
104104
setAppIndex,
105105
intervalID,
106106
setIntervalID,

app/context/DashboardContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const DashboardContextProvider = React.memo((props: any) => {
4646
const [applications, setApplications] = useState<string[][]>([]);
4747
const [mode, setMode] = useState<string>('light');
4848

49-
49+
5050
const getApplications = useCallback(() => {
5151
const result = ipcRenderer.sendSync('getApps');
5252
setApplications(result);
@@ -64,7 +64,7 @@ const DashboardContextProvider = React.memo((props: any) => {
6464
// console.log('applications: ', applications);
6565
// console.log('new app to add: ', newApp);
6666
// setApplications([...applications, newApp]);
67-
// console.log('the current application that was added is : ', result);
67+
console.log('the current application that was added is : ', result);
6868
}, []);
6969

7070
const addAwsApp = useCallback((awsFields: AwsFields) => {

app/context/DockerContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ const DockerContextProvider: React.FC<Props> = React.memo((props) => {
3737

3838
ipcRenderer.on('dockerResponse', (data: any) => {
3939
let result;
40-
if (tryParseJSON(data)) result = JSON.parse(data);
40+
if (tryParseJSON(data)) {
41+
console.log('DockerContext.tsx line 41 result: ', result)
42+
result = JSON.parse(data);
43+
}
4144
const newDockerData = result[0] || {};
4245
console.log(newDockerData);
4346
setDockerData(newDockerData);

app/context/HealthContext.tsx

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,80 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
5252
* @function fetchEventData - sending a request to the backend to retrieve data.
5353
* Data is then parsed and setHealthData is called with the transformed information.
5454
*/
55-
const fetchHealthData = useCallback(serv => {
55+
56+
const fetchHealthData = useCallback(async (serv) => {
5657
ipcRenderer.removeAllListeners('healthResponse');
5758

5859
let temp: HealthDataObject[] = [];
60+
//Promise.all(
61+
let promises = await Promise.all(serv.map( async (service: string) => {
62+
63+
try {
64+
const newPromise = await new Promise((resolve, reject) => {
65+
ipcRenderer.send('healthRequest', `${service}-containerinfos`);
66+
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
67+
let result: object[];
68+
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
69+
result = JSON.parse(data);
70+
console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
71+
// if (result && result.length && service === Object.keys(result[0])[0]) {
72+
resolve(result[0]);
73+
// }
74+
}
75+
});
76+
})
77+
console.log('HealthContext.tsx line 75 newPromise: ', newPromise);
78+
// temp.push(newPromise);
79+
// if (checkServicesComplete(temp, serv)) {
80+
// setServices(serv);
81+
// let transformedData: any = {};
82+
// console.log('original healthData before transformation: ', temp);
83+
// transformedData = healthTransformer(temp);
84+
// console.log('healthData after tranformation: ', transformedData);
85+
// setHealthData(transformedData);
86+
// }
87+
} catch (err) {
88+
console.log("healthcontext.tsx ERROR: ", err);
89+
};
90+
}
91+
));
92+
}, []);
93+
// const fetchHealthData = useCallback(serv => {
94+
// ipcRenderer.removeAllListeners('healthResponse');
5995

60-
Promise.all(
61-
serv.map((service: string) => {
62-
return new Promise((resolve, reject) => {
63-
ipcRenderer.send('healthRequest', service);
64-
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
65-
let result: object[];
66-
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
67-
result = JSON.parse(data);
68-
if (result && result.length && service === Object.keys(result[0])[0]) {
69-
resolve(result[0]);
70-
}
71-
}
72-
});
73-
}).then((dt: any) => {
74-
temp.push(dt);
75-
if (checkServicesComplete(temp, serv)) {
76-
setServices(serv);
77-
let transformedData: any = {};
78-
console.log('original healthData before transformation: ', temp);
79-
transformedData = healthTransformer(temp);
80-
console.log('healthData after tranformation: ', transformedData);
81-
setHealthData(transformedData);
82-
}
83-
});
84-
})
85-
);
86-
}, []);
96+
// let temp: HealthDataObject[] = [];
97+
// //Promise.all(
98+
// const promises = serv.map((service: string) => {
99+
// return new Promise((resolve, reject) => {
100+
// ipcRenderer.send('healthRequest', `${service}-containerinfos`);
101+
// ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
102+
// let result: object[];
103+
// if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
104+
// result = JSON.parse(data);
105+
// console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
106+
// if (result && result.length && service === Object.keys(result[0])[0]) {
107+
// resolve(result[0]);
108+
// }
109+
// }
110+
// });
111+
// }).then((dt: any) => {
112+
// console.log('HealthContext.tsx line 75 dt: ', dt);
113+
// temp.push(dt);
114+
// if (checkServicesComplete(temp, serv)) {
115+
// setServices(serv);
116+
// let transformedData: any = {};
117+
// console.log('original healthData before transformation: ', temp);
118+
// transformedData = healthTransformer(temp);
119+
// console.log('healthData after tranformation: ', transformedData);
120+
// setHealthData(transformedData);
121+
// }
122+
// }).catch ((err) => {
123+
// console.log("healthcontext.tsx ERROR: ", err);
124+
// });
125+
// })
126+
// Promise.all(promises).then((results) => {console.log('results from promiseALL: ', results)});
127+
// //);
128+
// }, []);
87129

88130
const checkServicesComplete = (temp: any[], serv: string[]) => {
89131
if (temp.length !== serv.length) {

app/context/TempCodingHC.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//Version 12 - testing an async await version of "promiseALL" from HealthContext.tsx to get Docker example to pass result data out from the mongo fetch
2+
3+
const fetchHealthData = useCallback(async (serv) => {
4+
ipcRenderer.removeAllListeners('healthResponse');
5+
6+
let temp: HealthDataObject[] = [];
7+
//Promise.all(
8+
let promises = await Promise.all(serv.map( async (service: string) => {
9+
10+
try {
11+
const newPromise = await new Promise((resolve, reject) => {
12+
13+
ipcRenderer.send('healthRequest', `${service}-containerinfos`);
14+
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
15+
let result: object[];
16+
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
17+
result = JSON.parse(data);
18+
console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
19+
if (result && result.length && service === Object.keys(result[0])[0]) {
20+
resolve(result[0]);
21+
}
22+
}
23+
});
24+
})
25+
console.log('HealthContext.tsx line 75 newPromise: ', newPromise);
26+
temp.push(newPromise);
27+
if (checkServicesComplete(temp, serv)) {
28+
setServices(serv);
29+
let transformedData: any = {};
30+
console.log('original healthData before transformation: ', temp);
31+
transformedData = healthTransformer(temp);
32+
console.log('healthData after tranformation: ', transformedData);
33+
setHealthData(transformedData);
34+
}
35+
} catch (err) {
36+
console.log("healthcontext.tsx ERROR: ", err);
37+
};
38+
}
39+
));
40+
}, []);

chronos_npm_package/controllers/dockerHelper.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ const si = require('systeminformation');
22

33
/**
44
* Finds the data pt with containerName that matches microservice and extracts container ID, name, platform, and start time.
5-
* @param {*} microservice
5+
* @param {*} microservice
66
* @returns array of active containers (ea. container = an obj).
77
*/
88
async function getDockerContainer(microservice) {
99
try {
10-
10+
1111
const containers = await si.dockerContainers();
12-
const out = {};;
12+
const out = {};
1313
let found = false;
1414
for (let container of containers) {
1515
if (container.name === microservice) {
@@ -31,7 +31,7 @@ async function getDockerContainer(microservice) {
3131
} catch (e) {
3232
console.error(e);
3333
return e;
34-
}
34+
}
3535

3636
}
3737

electron/databases/mongo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mongoose from 'mongoose';
22
// import { MongoError } from 'mongodb';
3-
const testURL = '';
3+
const testURL = 'mongodb+srv://<username>:<password>@cluster0.axo7iyw.mongodb.net/';
44
// Mongoose connection wrapped in function that takes the index of the selected database as the parameter. This index is used to target the correct database for querying.
55
const connectMongoose = async (i:number, URI: string) => {
66
try {

electron/routes/data.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, username: string, i
6767
connectMongo(index, URI)
6868
.then((data) => {
6969
if (data) {
70-
console.log('Connected to user provided MongoDB database')
70+
console.log('Connected to user provided MongoDB database "data.ts"')
7171
message.sender.send('databaseConnected', true);
7272
} else {
73-
console.log('Failed to connect to database')
73+
console.log('Failed to connect to database "data.ts"')
7474
message.sender.send('databaseConnected', false);
7575
}
7676
})
77-
77+
7878
} else if (currentDatabaseType === 'SQL') {
7979
pool = await connectPostgres(index, URI);
8080
if (pool) {
@@ -100,7 +100,9 @@ ipcMain.on('servicesRequest', async (message: Electron.IpcMainEvent) => {
100100
console.log('CurrentDataBase TYPE:', currentDatabaseType);
101101
if (currentDatabaseType === 'MongoDB' ) {
102102
// Get all documents from the services collection
103+
//>>>>>
103104
result = await ServicesModel.find();
105+
console.log('result of MongoQuery: ', result);
104106
}
105107

106108
// SQL Database
@@ -111,7 +113,7 @@ ipcMain.on('servicesRequest', async (message: Electron.IpcMainEvent) => {
111113
result = result.rows;
112114
}
113115

114-
// console.log('Sending servicesResponse to frontend with the following result:', result);
116+
console.log('Sending servicesResponse to frontend with the following result:', result);
115117
// Async event emitter - send response
116118
message.sender.send('servicesResponse', JSON.stringify(result));
117119
// eslint-disable-next-line no-shadow
@@ -160,6 +162,7 @@ ipcMain.on('healthRequest', async (message: Electron.IpcMainEvent, service: stri
160162

161163
// Mongo Database
162164
if (currentDatabaseType === 'MongoDB') {
165+
console.log('database', currentDatabaseType, 'service', service)
163166
result = await mongoFetch(service);
164167
}
165168

@@ -172,7 +175,7 @@ ipcMain.on('healthRequest', async (message: Electron.IpcMainEvent, service: stri
172175
// result = await pool.query(query);
173176
// result = result.rows;
174177
}
175-
console.log('result', result)
178+
console.log('result data.ts line 177', result, result[0][`orders-containerinfos`][0])
176179
// Async event emitter - send response'
177180

178181
message.sender.send('healthResponse', JSON.stringify(result));
@@ -627,7 +630,7 @@ ipcMain.on(
627630
message.sender.send('awsAppInfoResponse', { typeOfService: '', region: '' , awsUrl: ''});
628631
}
629632
}
630-
633+
631634
}
632635
);
633636

@@ -690,8 +693,8 @@ ipcMain.on('eksMetricsRequest', async (message:Electron.IpcMainEvent, username:
690693
* @event awsAppInfoRequest - invoked in fetchAwsAppInfo in ipcRenderer
691694
* @desc Connects to user or guest database and returns a reponse object with the typeOfService,
692695
* region, and awsURL of the services at provided appIndex.
693-
* @params username:
694-
* index:
696+
* @params username:
697+
* index:
695698
*/
696699
ipcMain.on(
697700
'awsAppInfoRequest',

0 commit comments

Comments
 (0)