Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #570 from jecluis/wip-fix-hostname
Browse files Browse the repository at this point in the history
gravel: setting hostname must update state
  • Loading branch information
jecluis authored Jun 15, 2021
2 parents c4e369d + b4141a3 commit 1c26849
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('InstallCreateWizardPageComponent', () => {
it('should show notification only once [3]', fakeAsync(() => {
component.startBootstrap();
httpTesting
.match({ url: 'api/orch/hostname', method: 'PUT' })[0]
.match({ url: 'api/nodes/hostname', method: 'PUT' })[0]
.error(new ErrorEvent('Unknown error'), { status: 500 });
tick(5);
expect(toastrService.error).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
NodesService,
NodeStageEnum
} from '~/app/shared/services/api/nodes.service';
import { OrchService } from '~/app/shared/services/api/orch.service';
import { NotificationService } from '~/app/shared/services/notification.service';
import { PollService } from '~/app/shared/services/poll.service';

Expand Down Expand Up @@ -69,7 +68,6 @@ export class InstallCreateWizardPageComponent implements OnInit {
private localNodeService: LocalNodeService,
private nodesService: NodesService,
private notificationService: NotificationService,
private orchService: OrchService,
private pollService: PollService
) {}

Expand Down Expand Up @@ -150,7 +148,7 @@ export class InstallCreateWizardPageComponent implements OnInit {
* This step starts the bootstrap process
*/
startBootstrap(): void {
this.orchService.setHostname(this.context.config.hostname).subscribe({
this.nodesService.setHostname(this.context.config.hostname).subscribe({
complete: () => {
this.blockUI.start(translate(TEXT('Please wait, checking node status ...')));
this.pollNodeStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
StatusStageEnum
} from '~/app/shared/services/api/local.service';
import { NodesService } from '~/app/shared/services/api/nodes.service';
import { OrchService } from '~/app/shared/services/api/orch.service';
import { NotificationService } from '~/app/shared/services/notification.service';
import { PollService } from '~/app/shared/services/poll.service';

Expand Down Expand Up @@ -64,7 +63,6 @@ export class InstallJoinWizardPageComponent implements OnInit {
private localNodeService: LocalNodeService,
private nodesService: NodesService,
private notificationService: NotificationService,
private orchService: OrchService,
private pollService: PollService
) {}

Expand Down Expand Up @@ -122,7 +120,7 @@ export class InstallJoinWizardPageComponent implements OnInit {
this.context.stepperVisible = false;
this.blockUI.start(translate(TEXT('Please wait, start joining existing cluster ...')));
concat(
this.orchService.setHostname(this.context.config.hostname),
this.nodesService.setHostname(this.context.config.hostname),
this.nodesService.join({
address: `${this.context.config.address}:${this.context.config.port}`,
token: this.context.config.token
Expand Down Expand Up @@ -165,10 +163,12 @@ export class InstallJoinWizardPageComponent implements OnInit {
switch (res.node_stage) {
case StatusStageEnum.none:
case StatusStageEnum.unknown:
this.context.stage = 'unknown';
this.handleError(TEXT('Failed to join existing cluster.'));
break;
case StatusStageEnum.ready:
this.context.stage = 'unknown';
this.context.stage = 'joined';
this.context.stepperVisible = true;
this.blockUI.stop();
this.stepper?.next();
break;
Expand Down
12 changes: 12 additions & 0 deletions src/glass/src/app/shared/services/api/nodes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export type DiskSolution = {
possible: boolean;
};

export type SetHostnameRequest = {
name: string;
};

@Injectable({
providedIn: 'root'
})
Expand Down Expand Up @@ -116,4 +120,12 @@ export class NodesService {
deploymentDiskSolution(): Observable<DiskSolution> {
return this.http.get<DiskSolution>(`${this.deploymentURL}/disksolution`);
}

/**
* Setup hostname
*/
setHostname(name: string): Observable<boolean> {
const request: SetHostnameRequest = { name };
return this.http.put<boolean>(`${this.url}/hostname`, request);
}
}
11 changes: 0 additions & 11 deletions src/glass/src/app/shared/services/api/orch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ export type HostDevices = {
devices: Device[];
};

export type SetHostnameRequest = {
name: string;
};

@Injectable({
providedIn: 'root'
})
Expand All @@ -65,11 +61,4 @@ export class OrchService {
return this.http.get<{ [hostName: string]: HostDevices }>(`${this.url}/devices`);
}

/**
* Setup hostname
*/
setHostname(name: string): Observable<boolean> {
const request: SetHostnameRequest = { name };
return this.http.put<boolean>(`${this.url}/hostname`, request);
}
}
18 changes: 18 additions & 0 deletions src/gravel/api/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class StartDeploymentRequest(BaseModel):
ntpaddr: str = Field(title="NTP server address")


class SetHostnameRequest(BaseModel):
name: str = Field(min_length=1, title="The system hostname")


@router.get("/deployment/disksolution", response_model=DiskSolution)
async def node_get_disk_solution(request: Request) -> DiskSolution:
"""
Expand Down Expand Up @@ -217,6 +221,20 @@ async def nodes_get_token(request: Request):
)


@router.put("/hostname", response_model=bool)
async def put_hostname(request: Request, req: SetHostnameRequest) -> bool:
nodemgr: NodeMgr = request.app.state.nodemgr
if nodemgr.deployment_state.deployed or nodemgr.deployment_state.ready:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Node already deployed")
try:
await nodemgr.set_hostname(req.name)
except Exception as e:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=str(e))
return True


router.add_websocket_route( # pyright: reportUnknownMemberType=false
"/nodes/ws",
IncomingConnection
Expand Down
25 changes: 1 addition & 24 deletions src/gravel/api/orch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
from fastapi.routing import APIRouter
from fastapi.logger import logger as fastapi_logger
from fastapi import HTTPException, status, Request
from pydantic import BaseModel, Field
from pydantic import BaseModel
from typing import Dict, List

from gravel.controllers.nodes.mgr import NodeMgr
from gravel.controllers.orch.models import OrchDevicesPerHostModel
from gravel.controllers.orch.system import set_hostname
from gravel.controllers.orch.orchestrator \
import Orchestrator

Expand Down Expand Up @@ -55,14 +53,6 @@ class HostsDevicesModel(BaseModel):
devices: List[DeviceModel]


class SetHostnameRequest(BaseModel):
name: str = Field(min_length=1, title="The system hostname")


class SetNtpRequest(BaseModel):
addr: str


@router.get("/hosts", response_model=List[HostModel])
def get_hosts(request: Request) -> List[HostModel]:
orch = Orchestrator(request.app.state.gstate.ceph_mgr)
Expand Down Expand Up @@ -136,16 +126,3 @@ async def get_pubkey(request: Request) -> str:
except Exception as e:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=str(e))


@router.put("/hostname", response_model=bool)
async def put_hostname(request: Request, req: SetHostnameRequest) -> bool:
nodemgr: NodeMgr = request.app.state.nodemgr
if nodemgr.deployment_state.deployed or nodemgr.deployment_state.ready:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Node already deployed")
try:
return set_hostname(req.name)
except Exception as e:
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=str(e))
14 changes: 14 additions & 0 deletions src/gravel/controllers/nodes/mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
DeploymentState,
NodeDeployment
)
from gravel.controllers.nodes.host import HostnameCtlError, set_hostname
from gravel.controllers.orch.ceph import (
CephCommandError,
Mon
Expand Down Expand Up @@ -307,6 +308,19 @@ def gen() -> str:
tokenstr = '-'.join(gen() for _ in range(4))
return tokenstr

async def set_hostname(self, name: str) -> None:
logger.info(f"set hostname '{name}'")
try:
set_hostname(name)
except HostnameCtlError as e:
logger.error(f"set hostname: {e.message}")
raise e
except Exception as e:
logger.error(f"set hostname: {str(e)}")
raise NodeError(f"setting hostname: {str(e)}")
self._state.hostname = name
await self._save_state()

async def join(self, leader_address: str, token: str) -> bool:
logger.debug(
f"join > with leader {leader_address}, token: {token}"
Expand Down

0 comments on commit 1c26849

Please sign in to comment.