-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/ping services #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Xemka
wants to merge
59
commits into
main
Choose a base branch
from
feature/ping-services
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
cf6b853
Add cron schedule to env.example
Xemka dc9d2c9
Update yarn.lock
Xemka 8aa8aaa
Add cron schedule listener
Xemka 6f17fd1
Add update message to types
Xemka 456202e
Update package.json
Xemka 6a87e1a
Add service status to types
Xemka d522262
Add update message to outgoing messages
Xemka e77b00e
Fix type of services
Xemka b9edd24
Added a scheduled launch to index.ts
Xemka befa352
Added statuses reader
Xemka 1cd6462
Refactor statuses.ts
Xemka 17d9318
Added a file for searching one workspace
Xemka 94ecadb
Merge branch 'main' of https://github.com/codex-team/devops-toolbox-a…
Xemka 12ad87d
Refactoring
Xemka a690d43
Add axios to package.json
Xemka ffcf8c4
Refactor statuses.ts
Xemka af9773a
Added services aggregation type
Xemka e78f88b
Added use of mongodb aggregations in statuses.ts
Xemka fe96048
Added aggregations function in workspaces service
Xemka d392ebd
Merge branch 'main' of https://github.com/codex-team/devops-toolbox-a…
Xemka b697b28
Moved aggregation condition to services
Xemka 4be581c
Refactored types and promises
Xemka f722f38
Merge branch 'main' into feature/ping-services
fabled228 af93395
fixes
fabled228 869b489
Added ping of services
fabled228 5816b0d
eslint fixes
fabled228 3f427b2
fixes of commits
fabled228 4357669
removed logs
fabled228 5bcc722
Updating statuses for each workspace now not for users
fabled228 19cfef1
axios removed
fabled228 97f0726
changed collection name
fabled228 3fd12d3
Comments added
fabled228 5e9d454
removed excess cycle
fabled228 9b04c96
Update statuses.ts
fabled228 0fd1568
Update workspace.ts
fabled228 597ffcd
Update tsconfig.json
fabled228 6254fb5
fixed comments
fabled228 7e4ae5f
fixed finding of workspaces to return for 1 user
fabled228 5fcce7c
fixed names,comments and logic
fabled228 7ef4f60
fixed pinging
fabled228 6bdbf6c
remove logs
fabled228 3cc0457
fix of names and added new method to StatusesController
fabled228 9303915
fixed pingProjects
fabled228 00c9538
Update statuses.ts
fabled228 185d932
added export
fabled228 3670d6a
refactoring
fabled228 2c59cca
Update statuses.ts
fabled228 228d0ac
changed workspace aggregation
fabled228 cdfb9f3
refactoring
fabled228 3151c73
removed excess code
fabled228 2044caa
removed aggregations
fabled228 f6e58e9
fixed names
fabled228 f0c14e7
removed extend db operations
fabled228 1436e8f
refactoring
fabled228 b63e434
added docs
fabled228 28715eb
fixes
fabled228 2503fdc
Update servicePayload.ts
fabled228 8cc4b4f
docs
fabled228 b6f10b7
Update index.ts
fabled228 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import ping from 'ping'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars-experimental,@typescript-eslint/no-unused-vars | ||
import app from './../app'; | ||
import WorkspacesService from './../services/workspace'; | ||
import ServerProjectsStatuses, { ProjectStatus } from '../types/serverProjectsStatuses'; | ||
import Workspace from './../types/workspace'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import Client from 'ctproto/build/src/server/client'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import { DevopsToolboxAuthData } from '../types/api/responses/authorize'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import { ApiOutgoingMessage, ApiResponse } from '../types'; | ||
import Server from '../services/server'; | ||
import { NginxPayload } from '../types/servicePayload'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
|
||
/** | ||
* Statuses controller to work with updating/checking/sending statuses of servers' statuses for each workspace | ||
*/ | ||
export default class StatusesController { | ||
/** | ||
* Update statuses and send to logged users | ||
*/ | ||
public static async updateStatuses(): Promise<void> { | ||
const workspaces: Workspace[] | null = await WorkspacesService.find(); | ||
|
||
/** | ||
* If workspaces exist,then updating statuses for them | ||
*/ | ||
if (workspaces) { | ||
for (const workspace of workspaces) { | ||
/** | ||
* For each server of workspace update statuses | ||
*/ | ||
for (const s of workspace.servers) { | ||
for (const service of s.services) { | ||
/** | ||
* If type of service is nginx, server's projects are pinged | ||
*/ | ||
if (service.type === 'nginx') { | ||
const projectsStatuses = await this.pingProjects(service.payload as NginxPayload[]); | ||
const serverProjectsStatuses: ServerProjectsStatuses = { | ||
projectsStatuses, | ||
serverToken: s.token, | ||
} as ServerProjectsStatuses; | ||
|
||
await Server.updateServicesStatuses(serverProjectsStatuses); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Project availability check | ||
* | ||
* @param serverProject - array of workspace server's projects | ||
*/ | ||
public static async checkProjectAvailability(serverProject: string): Promise<ProjectStatus> { | ||
if (serverProject === '') { | ||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { | ||
host: 'Unnamed host', | ||
isOnline: false, | ||
}; | ||
} else { | ||
const pingServer = await ping.promise.probe(serverProject); | ||
|
||
return { | ||
host: serverProject, | ||
isOnline: pingServer.alive, | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Ping projects of some server | ||
* | ||
* @param payload - list of project of payload of some service of some server | ||
*/ | ||
public static async pingProjects(payload: NginxPayload[]): Promise<ProjectStatus[]> { | ||
const projectsStatuses:ProjectStatus[] = []; | ||
|
||
for (const payloadElement of payload) { | ||
const projectStatus = await StatusesController.checkProjectAvailability(payloadElement.serverName); | ||
|
||
projectsStatuses.push(projectStatus); | ||
} | ||
|
||
return projectsStatuses; | ||
} | ||
|
||
/** | ||
* Send statuses to clients | ||
* | ||
* @param statuses - array of statuses of all client services | ||
* @param user - user | ||
*/ | ||
// public static sendStatuses(statuses: ServerProjectsStatuses[], user: Client<DevopsToolboxAuthData, ApiResponse, ApiOutgoingMessage>): void { | ||
// if (typeof user.authData.userToken === 'string') { | ||
// app.context.transport | ||
// .clients | ||
// .find((client) => client.authData.userToken === user.authData.userToken) | ||
// .send('statuses-updated', { statuses }); | ||
// } | ||
// } | ||
Comment on lines
+100
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если это тебе не нужно, то можно убрать это вообще There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. комменты уберу в некст реквесте |
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import mongoose from '..'; | ||
import ServerProjectsStatuses from '../../types/serverProjectsStatuses'; | ||
|
||
/** | ||
* Project status Schema | ||
*/ | ||
const serverProjectsStatusesSchema: mongoose.Schema = new mongoose.Schema({ | ||
/** | ||
* Workspace server's token | ||
*/ | ||
serverToken: { | ||
type: String, | ||
required: true, | ||
}, | ||
/** | ||
* Workspace server's projects' names and statuses | ||
*/ | ||
projectsStatuses: [ { | ||
/** | ||
* Host name | ||
*/ | ||
host: { | ||
type: String, | ||
required: true, | ||
}, | ||
/** | ||
* host status | ||
*/ | ||
isOnline: { | ||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: Boolean, | ||
required: true, | ||
}, | ||
} ], | ||
}); | ||
|
||
export default mongoose.model<ServerProjectsStatuses>('server_projects_statuses', serverProjectsStatusesSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import mongoose from '../database'; | ||
import IServerProjectsStatuses from '../types/serverProjectsStatuses'; | ||
import ServerProjectsStatuses from '../database/models/serverServicesStatuses'; | ||
|
||
/** | ||
* Server of workspace with token,services and projects | ||
*/ | ||
export default class Server { | ||
/** | ||
* Add new server | ||
* | ||
* @param server - new server | ||
*/ | ||
public static async add(server: IServerProjectsStatuses): Promise<IServerProjectsStatuses | null> { | ||
const newServer = new ServerProjectsStatuses(server); | ||
|
||
return newServer.save(); | ||
} | ||
|
||
/** | ||
* Update of server projects' statuses in DB | ||
* | ||
* @param serverProjectsStatuses - server projects' statuses and server token | ||
*/ | ||
public static async updateServicesStatuses(serverProjectsStatuses: IServerProjectsStatuses): Promise<mongoose.Document> { | ||
const server = await ServerProjectsStatuses.findOne({ serverToken: serverProjectsStatuses.serverToken }); | ||
|
||
if (!server) { | ||
await this.add(serverProjectsStatuses); | ||
} | ||
|
||
return ServerProjectsStatuses.updateOne({ | ||
serverToken: serverProjectsStatuses.serverToken, | ||
}, { | ||
$set: { | ||
projectsStatuses: serverProjectsStatuses.projectsStatuses, | ||
}, | ||
|
||
}, { | ||
new: true, | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NewMessage } from 'ctproto/types'; | ||
import ServerProjectsStatuses from '../../serverProjectsStatuses'; | ||
|
||
/** | ||
* Data about the updated statuses | ||
*/ | ||
interface StatusesUpdatedPayload { | ||
/** | ||
* The updated workspace | ||
*/ | ||
projectsStatuses: ServerProjectsStatuses; | ||
} | ||
|
||
/** | ||
* Describes the outgoing message that will be sent when statuses of services will be updated | ||
*/ | ||
export default interface StatusesUpdatedMessage extends NewMessage<StatusesUpdatedPayload> { | ||
type: 'statuses-updated'; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
/** | ||
* Project status of the server | ||
*/ | ||
export interface ProjectStatus { | ||
/** | ||
* Name of host | ||
*/ | ||
host: string; | ||
/** | ||
* State of host (online/offline) | ||
*/ | ||
isOnline: boolean; | ||
} | ||
/** | ||
* Status of service in workspace | ||
*/ | ||
export default interface ServerProjectsStatuses extends mongoose.Document { | ||
/** | ||
* Server's (containing the services) id | ||
*/ | ||
serverToken: string; | ||
/** | ||
* Projects with their statuses of the server | ||
*/ | ||
projectsStatuses: ProjectStatus[]; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что за беспредел
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В следующем реквесте уберу..