From f2a07907a0de12ba6daf67bab98e59b9f84a0ac3 Mon Sep 17 00:00:00 2001 From: hawk9821 <39961809+hawk9821@users.noreply.github.com> Date: Fri, 17 May 2024 23:57:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=90=AFcheckstyle=EF=BC=8C=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=E5=BC=95?= =?UTF-8?q?=E8=B5=B7=E7=9A=84=E5=86=B2=E7=AA=81=20(#557)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Bug] Doris] DDP1.2.2,使用doris官方包安装be失败 #539 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * Update KyuubiServerHandlerStrategy.java [Feature] 开启checkstyle, 统一代码风格,避免代码风格引起的冲突 #555 * 修改github ci * 修改github ci * 修改github ci * 修改github ci --- .github/workflows/maven.yaml | 15 +- datasophon-api/pom.xml | 10 +- .../api/DataSophonApplicationServer.java | 23 +- .../api/configuration/AppConfiguration.java | 22 +- .../configuration/ConfigPropertiesExtend.java | 36 +- .../configuration/DatabaseMigrationAware.java | 8 +- .../api/controller/AlertGroupController.java | 28 +- .../ClusterAlertGroupMapController.java | 26 +- .../ClusterAlertHistoryController.java | 24 +- .../ClusterAlertQuotaController.java | 28 +- .../controller/ClusterGroupController.java | 22 +- .../api/controller/ClusterHostController.java | 42 +- .../api/controller/ClusterInfoController.java | 25 +- .../controller/ClusterKerberosController.java | 14 +- .../ClusterNodeLabelController.java | 10 +- .../ClusterQueueCapacityController.java | 28 +- .../api/controller/ClusterRackController.java | 14 +- .../controller/ClusterRoleUserController.java | 22 +- .../ClusterServiceCommandController.java | 38 +- ...erServiceCommandHostCommandController.java | 26 +- .../ClusterServiceCommandHostController.java | 22 +- .../ClusterServiceDashboardController.java | 8 +- ...lusterServiceInstanceConfigController.java | 20 +- .../ClusterServiceInstanceController.java | 28 +- ...terServiceInstanceRoleGroupController.java | 24 +- ...usterServiceRoleGroupConfigController.java | 26 +- ...erServiceRoleInstanceConfigController.java | 24 +- .../ClusterServiceRoleInstanceController.java | 20 +- ...erServiceRoleInstanceWebuisController.java | 26 +- .../api/controller/ClusterUserController.java | 24 +- .../ClusterUserGroupController.java | 22 +- .../ClusterYarnQueueController.java | 31 +- .../ClusterYarnSchedulerController.java | 26 +- .../api/controller/FrameInfoController.java | 22 +- .../controller/FrameServiceController.java | 47 +- .../FrameServiceRoleController.java | 28 +- .../api/controller/HostInstallController.java | 42 +- .../api/controller/LoginController.java | 30 +- .../controller/NoticeGroupUserController.java | 24 +- .../api/controller/ParcelController.java | 203 +++---- .../api/controller/RoleInfoController.java | 24 +- .../controller/ServiceInstallController.java | 49 +- .../api/controller/UserInfoController.java | 34 +- .../api/exceptions/ApiException.java | 3 +- .../api/exceptions/ApiExceptionHandler.java | 23 +- .../interceptor/LocaleChangeInterceptor.java | 6 +- .../interceptor/LoginHandlerInterceptor.java | 12 +- .../interceptor/UserPermissionHandler.java | 22 +- .../api/migration/DatabaseMigration.java | 484 ++++++++-------- .../datasophon/api/migration/Migration.java | 132 ++--- .../datasophon/api/migration/ScriptType.java | 13 +- .../api/security/AuthenticationType.java | 6 +- .../api/security/Authenticator.java | 4 +- .../api/security/PasswordAuthenticator.java | 10 +- .../api/security/SecurityConfig.java | 16 +- .../api/security/UserPermission.java | 2 +- .../meta/DDP-1.2.2/DORIS/service_ddl.json | 3 +- datasophon-common/pom.xml | 76 +-- .../java/com/datasophon/common/Constants.java | 79 +-- .../datasophon/common/cache/CacheUtils.java | 20 +- .../common/command/BaseCommand.java | 24 +- .../common/command/BaseCommandResult.java | 4 +- .../CheckCommandExecuteProgressCommand.java | 6 +- .../CheckServiceExecuteStateCommand.java | 6 +- .../common/command/ClusterCommand.java | 10 +- .../command/DispatcherHostAgentCommand.java | 8 +- .../common/command/ExecuteCmdCommand.java | 6 +- .../command/ExecuteServiceRoleCommand.java | 22 +- .../common/command/FileOperateCommand.java | 6 +- .../command/GenerateAlertConfigCommand.java | 2 +- .../command/GenerateHostPrometheusConfig.java | 2 +- .../GeneratePrometheusConfigCommand.java | 8 +- .../command/GenerateRackPropCommand.java | 5 +- .../command/GenerateSRPromConfigCommand.java | 10 +- .../command/GenerateServiceConfigCommand.java | 14 +- .../command/GenerateStarRocksHAMessage.java | 4 +- .../common/command/GetLogCommand.java | 6 +- .../common/command/HdfsEcCommand.java | 2 +- .../common/command/HostCheckCommand.java | 8 +- .../common/command/HostInfoCollectResult.java | 4 +- .../command/InstallServiceRoleCommand.java | 25 +- .../InstallServiceRoleCommandConfirm.java | 2 +- .../InstallServiceRoleCommandResult.java | 4 +- .../common/command/OlapOpsType.java | 19 +- .../common/command/OlapSqlExecCommand.java | 6 +- .../common/command/PingCommand.java | 8 +- .../common/command/ServiceCheckCommand.java | 4 +- .../command/ServiceRoleOperateCommand.java | 22 +- .../ServiceRoleOperateCommandResult.java | 2 +- .../command/StartExecuteCommandCommand.java | 8 +- .../command/StartScheduledTaskCommand.java | 2 +- .../command/SubmitActiveTaskNodeCommand.java | 6 +- .../remote/CreateUnixGroupCommand.java | 2 +- .../command/remote/CreateUnixUserCommand.java | 6 +- .../command/remote/DelUnixGroupCommand.java | 2 +- .../command/remote/DelUnixUserCommand.java | 4 +- .../remote/GenerateKeytabFileCommand.java | 6 +- .../common/enums/ClusterCommandType.java | 4 +- .../datasophon/common/enums/CommandType.java | 27 +- .../datasophon/common/enums/InstallState.java | 17 +- .../datasophon/common/enums/ReplyType.java | 2 +- .../common/enums/ServiceRoleType.java | 14 +- .../common/exception/AkkaRemoteException.java | 6 +- .../lifecycle/ServerLifeCycleException.java | 4 +- .../lifecycle/ServerLifeCycleManager.java | 22 +- .../common/lifecycle/ServerStatus.java | 10 +- .../common/model/AkkaRemoteReply.java | 11 +- .../datasophon/common/model/AlertItem.java | 14 +- .../datasophon/common/model/CheckResult.java | 6 +- .../datasophon/common/model/ConfigWriter.java | 2 +- .../java/com/datasophon/common/model/DAG.java | 158 +++--- .../com/datasophon/common/model/DAGGraph.java | 94 ++-- .../common/model/ExecCmdResult.java | 12 +- .../datasophon/common/model/ExternalLink.java | 6 +- .../datasophon/common/model/Generators.java | 14 +- .../com/datasophon/common/model/HostInfo.java | 26 +- .../common/model/HostServiceRoleMapping.java | 5 +- .../com/datasophon/common/model/ProcInfo.java | 12 +- .../datasophon/common/model/PromDataInfo.java | 4 +- .../common/model/PromMetricInfo.java | 15 +- .../common/model/PromResponceInfo.java | 4 +- .../common/model/PromResultInfo.java | 6 +- .../com/datasophon/common/model/RunAs.java | 4 +- .../common/model/ServiceConfig.java | 38 +- .../model/ServiceExecuteResultMessage.java | 12 +- .../datasophon/common/model/ServiceInfo.java | 26 +- .../datasophon/common/model/ServiceNode.java | 8 +- .../common/model/ServiceNodeEdge.java | 2 +- .../common/model/ServiceRoleHostMapping.java | 4 +- .../common/model/ServiceRoleInfo.java | 54 +- .../common/model/ServiceRoleRunner.java | 6 +- .../common/model/SimpleServiceConfig.java | 6 +- .../common/model/StartWorkerMessage.java | 6 +- .../model/StartWorkerMessageConfirmed.java | 4 +- .../model/UpdateCommandHostMessage.java | 10 +- .../common/model/UpdateCommandMessage.java | 4 +- .../common/model/WorkerServiceMessage.java | 17 +- .../common/utils/CollectionUtils.java | 53 +- .../common/utils/EncryptionUtils.java | 9 +- .../datasophon/common/utils/ExecResult.java | 18 +- .../datasophon/common/utils/FileUtils.java | 42 +- .../datasophon/common/utils/HostUtils.java | 24 +- .../com/datasophon/common/utils/IOUtils.java | 2 +- .../datasophon/common/utils/OlapUtils.java | 41 +- .../common/utils/PlaceholderUtils.java | 18 +- .../common/utils/PromInfoUtils.java | 20 +- .../common/utils/PropertyUtils.java | 49 +- .../com/datasophon/common/utils/Result.java | 29 +- .../datasophon/common/utils/ShellUtils.java | 45 +- .../common/utils/ThrowableUtils.java | 2 +- datasophon-domain/pom.xml | 11 +- .../alert/gateway/AlertHistoryGateway.java | 7 +- .../domain/alert/model/AlertHistory.java | 4 +- .../domain/alert/model/AlertLabels.java | 4 +- .../domain/alert/model/AlertMessage.java | 8 +- .../datasophon/domain/alert/model/Alerts.java | 2 +- .../domain/alert/model/Annotations.java | 4 +- .../domain/host/enums/HostState.java | 18 +- .../datasophon/domain/host/enums/MANAGED.java | 18 +- .../domain/host/model/DynamicHostProp.java | 6 +- .../datasophon/domain/host/model/Host.java | 16 +- .../domain/host/model/ServiceRole.java | 4 +- .../dao/alert/AlertHistoryGatewayImpl.java | 24 +- .../dao/entity/AlertGroupEntity.java | 12 +- .../dao/entity/ClusterAlertExpression.java | 6 +- .../dao/entity/ClusterAlertGroupMap.java | 6 +- .../dao/entity/ClusterAlertHistory.java | 16 +- .../dao/entity/ClusterAlertQuota.java | 16 +- .../dao/entity/ClusterAlertRule.java | 6 +- .../datasophon/dao/entity/ClusterGroup.java | 12 +- .../datasophon/dao/entity/ClusterHostDO.java | 22 +- .../dao/entity/ClusterInfoEntity.java | 10 +- .../dao/entity/ClusterNodeLabelEntity.java | 6 +- .../dao/entity/ClusterQueueCapacity.java | 10 +- .../datasophon/dao/entity/ClusterRack.java | 6 +- .../dao/entity/ClusterRoleUserEntity.java | 6 +- .../entity/ClusterServiceCommandEntity.java | 14 +- ...lusterServiceCommandHostCommandEntity.java | 20 +- .../ClusterServiceCommandHostEntity.java | 10 +- .../dao/entity/ClusterServiceDashboard.java | 6 +- .../ClusterServiceInstanceConfigEntity.java | 10 +- .../entity/ClusterServiceInstanceEntity.java | 18 +- .../ClusterServiceInstanceRoleGroup.java | 8 +- .../entity/ClusterServiceRoleGroupConfig.java | 6 +- ...lusterServiceRoleInstanceConfigEntity.java | 29 +- .../ClusterServiceRoleInstanceEntity.java | 14 +- .../ClusterServiceRoleInstanceWebuis.java | 10 +- .../datasophon/dao/entity/ClusterUser.java | 14 +- .../dao/entity/ClusterUserGroup.java | 10 +- .../dao/entity/ClusterVariable.java | 15 +- .../dao/entity/ClusterYarnQueue.java | 16 +- .../dao/entity/ClusterYarnScheduler.java | 8 +- .../com/datasophon/dao/entity/ClusterZk.java | 6 +- .../dao/entity/FrameInfoEntity.java | 8 +- .../dao/entity/FrameServiceEntity.java | 30 +- .../dao/entity/FrameServiceRoleEntity.java | 18 +- .../dao/entity/InstallStepEntity.java | 6 +- .../dao/entity/NoticeGroupEntity.java | 6 +- .../dao/entity/NoticeGroupUserEntity.java | 6 +- .../datasophon/dao/entity/RoleInfoEntity.java | 6 +- .../datasophon/dao/entity/SessionEntity.java | 6 +- .../datasophon/dao/entity/UserInfoEntity.java | 8 +- .../com/datasophon/dao/enums/AlertLevel.java | 18 +- .../datasophon/dao/enums/ClusterState.java | 28 +- .../datasophon/dao/enums/CommandState.java | 18 +- .../com/datasophon/dao/enums/NeedRestart.java | 18 +- .../com/datasophon/dao/enums/QuotaState.java | 18 +- .../com/datasophon/dao/enums/RoleType.java | 17 +- .../dao/enums/ServiceRoleState.java | 18 +- .../datasophon/dao/enums/ServiceState.java | 18 +- .../com/datasophon/dao/enums/UserType.java | 18 +- .../dao/mapper/AlertGroupMapper.java | 2 +- .../mapper/ClusterAlertExpressionMapper.java | 2 +- .../mapper/ClusterAlertGroupMapMapper.java | 2 +- .../dao/mapper/ClusterAlertHistoryMapper.java | 2 +- .../dao/mapper/ClusterAlertQuotaMapper.java | 2 +- .../dao/mapper/ClusterAlertRuleMapper.java | 2 +- .../dao/mapper/ClusterGroupMapper.java | 2 +- .../dao/mapper/ClusterHostMapper.java | 4 +- .../dao/mapper/ClusterInfoMapper.java | 2 +- .../mapper/ClusterQueueCapacityMapper.java | 2 +- .../dao/mapper/ClusterRackMapper.java | 2 +- .../dao/mapper/ClusterRoleUserMapper.java | 2 +- ...lusterServiceCommandHostCommandMapper.java | 2 +- .../ClusterServiceCommandHostMapper.java | 2 +- .../mapper/ClusterServiceCommandMapper.java | 2 +- .../mapper/ClusterServiceDashboardMapper.java | 2 +- .../ClusterServiceInstanceConfigMapper.java | 2 +- .../mapper/ClusterServiceInstanceMapper.java | 2 +- ...ClusterServiceInstanceRoleGroupMapper.java | 2 +- .../ClusterServiceRoleGroupConfigMapper.java | 2 +- ...lusterServiceRoleInstanceConfigMapper.java | 2 +- .../ClusterServiceRoleInstanceMapper.java | 4 +- ...lusterServiceRoleInstanceWebuisMapper.java | 2 +- .../dao/mapper/ClusterUserGroupMapper.java | 2 +- .../dao/mapper/ClusterUserMapper.java | 2 +- .../dao/mapper/ClusterVariableMapper.java | 2 +- .../dao/mapper/ClusterYarnQueueMapper.java | 2 +- .../mapper/ClusterYarnSchedulerMapper.java | 2 +- .../dao/mapper/ClusterZkMapper.java | 2 +- .../dao/mapper/FrameInfoMapper.java | 2 +- .../dao/mapper/FrameServiceMapper.java | 2 +- .../dao/mapper/FrameServiceRoleMapper.java | 2 +- .../dao/mapper/InstallStepMapper.java | 2 +- .../dao/mapper/NoticeGroupUserMapper.java | 2 +- .../datasophon/dao/mapper/RoleInfoMapper.java | 2 +- .../datasophon/dao/mapper/SessionMapper.java | 6 +- .../datasophon/dao/mapper/UserInfoMapper.java | 2 +- .../dao/model/ClusterQueueCapacityList.java | 6 +- .../com/datasophon/dao/model/ComponentVO.java | 12 +- .../java/com/datasophon/dao/model/Links.java | 4 +- .../datasophon/dao/model/ParcelInfoVO.java | 22 +- .../dao/model/ServiceOperateModel.java | 6 +- datasophon-service/pom.xml | 15 +- .../java/com/datasophon/api/enums/Status.java | 25 +- .../api/exceptions/BusinessException.java | 21 +- .../api/exceptions/ServiceException.java | 15 +- .../com/datasophon/api/load/ConfigBean.java | 4 +- .../datasophon/api/load/GlobalVariables.java | 8 +- .../datasophon/api/load/LoadServiceMeta.java | 199 ++++--- .../api/load/ServiceConfigFileMap.java | 8 +- .../datasophon/api/load/ServiceConfigMap.java | 8 +- .../datasophon/api/load/ServiceInfoMap.java | 8 +- .../api/load/ServiceRoleJmxMap.java | 8 +- .../datasophon/api/load/ServiceRoleMap.java | 8 +- .../com/datasophon/api/master/ActorUtils.java | 66 +-- .../api/master/CancelCommandMap.java | 7 +- .../datasophon/api/master/ClusterActor.java | 83 +-- .../datasophon/api/master/DAGBuildActor.java | 58 +- .../api/master/DispatcherWorkerActor.java | 35 +- .../datasophon/api/master/HdfsECActor.java | 6 +- .../datasophon/api/master/HostCheckActor.java | 273 ++++----- .../api/master/HostConnectActor.java | 14 +- .../api/master/MasterNodeProcessingActor.java | 14 +- .../api/master/MasterServiceActor.java | 32 +- .../api/master/PrometheusActor.java | 72 +-- .../com/datasophon/api/master/RackActor.java | 10 +- .../api/master/RemoteEventActor.java | 4 +- .../api/master/ServiceCommandActor.java | 72 +-- .../api/master/ServiceExecuteResultActor.java | 18 +- .../api/master/SubmitTaskNodeActor.java | 18 +- .../api/master/WorkerServiceActor.java | 18 +- .../api/master/WorkerStartActor.java | 71 +-- .../api/master/alert/AlertActor.java | 78 +-- .../master/alert/ServiceRoleCheckActor.java | 17 +- .../handler/host/CheckWorkerMd5Handler.java | 2 +- .../handler/host/DecompressWorkerHandler.java | 4 +- .../handler/host/DispatcherWorkerHandler.java | 2 +- .../host/DispatcherWorkerHandlerChain.java | 6 +- .../handler/host/InstallJDKHandler.java | 6 +- .../handler/host/StartWorkerHandler.java | 24 +- .../handler/host/UploadWorkerHandler.java | 4 +- .../service/ServiceConfigureAsyncHandler.java | 92 ++-- .../service/ServiceConfigureHandler.java | 4 +- .../handler/service/ServiceHandler.java | 6 +- .../service/ServiceInstallHandler.java | 12 +- .../handler/service/ServiceStartHandler.java | 32 +- .../handler/service/ServiceStopHandler.java | 10 +- .../api/service/AlertGroupService.java | 7 +- .../ClusterAlertExpressionService.java | 5 +- .../service/ClusterAlertGroupMapService.java | 5 +- .../service/ClusterAlertHistoryService.java | 11 +- .../api/service/ClusterAlertQuotaService.java | 13 +- .../api/service/ClusterAlertRuleService.java | 5 +- .../api/service/ClusterGroupService.java | 17 +- .../api/service/ClusterInfoService.java | 19 +- .../api/service/ClusterKerberosService.java | 9 +- .../api/service/ClusterNodeLabelService.java | 13 +- .../service/ClusterQueueCapacityService.java | 9 +- .../api/service/ClusterRackService.java | 11 +- .../api/service/ClusterRoleUserService.java | 9 +- ...usterServiceCommandHostCommandService.java | 21 +- .../ClusterServiceCommandHostService.java | 13 +- .../service/ClusterServiceCommandService.java | 21 +- .../ClusterServiceDashboardService.java | 5 +- .../ClusterServiceInstanceConfigService.java | 9 +- ...lusterServiceInstanceRoleGroupService.java | 19 +- .../ClusterServiceInstanceService.java | 21 +- .../ClusterServiceRoleGroupConfigService.java | 11 +- ...usterServiceRoleInstanceConfigService.java | 5 +- .../ClusterServiceRoleInstanceService.java | 50 +- ...usterServiceRoleInstanceWebuisService.java | 17 +- .../api/service/ClusterUserGroupService.java | 13 +- .../api/service/ClusterUserService.java | 13 +- .../api/service/ClusterVariableService.java | 7 +- .../api/service/ClusterYarnQueueService.java | 7 +- .../service/ClusterYarnSchedulerService.java | 7 +- .../api/service/ClusterZkService.java | 7 +- .../api/service/FrameInfoService.java | 5 +- .../api/service/FrameServiceRoleService.java | 15 +- .../api/service/FrameServiceService.java | 15 +- .../api/service/InstallService.java | 23 +- .../api/service/NoticeGroupUserService.java | 5 +- .../api/service/RoleInfoService.java | 5 +- .../api/service/ServiceInstallService.java | 23 +- .../api/service/ServiceOperateStrategy.java | 2 +- .../api/service/SessionService.java | 9 +- .../api/service/UserInfoService.java | 9 +- .../api/service/host/ClusterHostService.java | 25 +- .../host/dto/QueryHostListPageDTO.java | 11 +- .../host/impl/ClusterHostServiceImpl.java | 98 ++-- .../service/impl/AlertGroupServiceImpl.java | 31 +- .../ClusterAlertExpressionServiceImpl.java | 6 +- .../impl/ClusterAlertGroupMapServiceImpl.java | 6 +- .../impl/ClusterAlertHistoryServiceImpl.java | 35 +- .../impl/ClusterAlertQuotaServiceImpl.java | 71 +-- .../impl/ClusterAlertRuleServiceImpl.java | 6 +- .../service/impl/ClusterGroupServiceImpl.java | 61 ++- .../service/impl/ClusterInfoServiceImpl.java | 106 ++-- .../impl/ClusterKerberosServiceImpl.java | 57 +- .../impl/ClusterNodeLabelServiceImpl.java | 54 +- .../impl/ClusterQueueCapacityServiceImpl.java | 48 +- .../service/impl/ClusterRackServiceImpl.java | 24 +- .../impl/ClusterRoleUserServiceImpl.java | 24 +- ...rServiceCommandHostCommandServiceImpl.java | 62 ++- .../ClusterServiceCommandHostServiceImpl.java | 28 +- .../ClusterServiceCommandServiceImpl.java | 96 ++-- .../ClusterServiceDashboardServiceImpl.java | 12 +- ...usterServiceInstanceConfigServiceImpl.java | 22 +- ...erServiceInstanceRoleGroupServiceImpl.java | 50 +- .../ClusterServiceInstanceServiceImpl.java | 102 ++-- ...sterServiceRoleGroupConfigServiceImpl.java | 16 +- ...rServiceRoleInstanceConfigServiceImpl.java | 6 +- ...ClusterServiceRoleInstanceServiceImpl.java | 103 ++-- ...rServiceRoleInstanceWebuisServiceImpl.java | 32 +- .../impl/ClusterUserGroupServiceImpl.java | 24 +- .../service/impl/ClusterUserServiceImpl.java | 67 +-- .../impl/ClusterVariableServiceImpl.java | 19 +- .../impl/ClusterYarnQueueServiceImpl.java | 43 +- .../impl/ClusterYarnSchedulerServiceImpl.java | 10 +- .../service/impl/ClusterZkServiceImpl.java | 14 +- .../service/impl/FrameInfoServiceImpl.java | 20 +- .../impl/FrameServiceRoleServiceImpl.java | 34 +- .../service/impl/FrameServiceServiceImpl.java | 32 +- .../api/service/impl/InstallServiceImpl.java | 118 ++-- .../impl/NoticeGroupUserServiceImpl.java | 6 +- .../api/service/impl/RoleInfoServiceImpl.java | 6 +- .../impl/ServiceInstallServiceImpl.java | 250 +++++---- .../api/service/impl/SessionServiceImpl.java | 62 ++- .../api/service/impl/UserInfoServiceImpl.java | 35 +- .../strategy/AlertManagerHandlerStrategy.java | 23 +- .../api/strategy/BEHandlerStartegy.java | 31 +- .../ElasticSearchHandlerStrategy.java | 39 +- .../api/strategy/FEHandlerStartegy.java | 37 +- .../strategy/FEObserverHandlerStartegy.java | 31 +- .../api/strategy/FlinkHandlerStrategy.java | 24 +- .../api/strategy/GrafanaHandlerStrategy.java | 20 +- .../api/strategy/HBaseHandlerStrategy.java | 18 +- .../HistoryServerHandlerStrategy.java | 21 +- .../HiveMetaStroreHandlerStrategy.java | 21 +- .../strategy/HiveServer2HandlerStrategy.java | 24 +- .../api/strategy/HttpFsHandlerStrategy.java | 26 +- .../strategy/JournalNodeHandlerStrategy.java | 27 +- .../api/strategy/KAdminHandlerStrategy.java | 33 +- .../api/strategy/KafkaHandlerStrategy.java | 18 +- .../api/strategy/KerberosHandlerStrategy.java | 32 +- .../api/strategy/Krb5KdcHandlerStrategy.java | 32 +- .../strategy/KyuubiServerHandlerStrategy.java | 102 ++-- .../api/strategy/NameNodeHandlerStrategy.java | 55 +- .../strategy/PrometheusHandlerStrategy.java | 32 +- .../api/strategy/RMHandlerStrategy.java | 50 +- .../strategy/RangerAdminHandlerStrategy.java | 53 +- .../api/strategy/ServiceHandlerAbstract.java | 31 +- .../api/strategy/ServiceRoleStrategy.java | 10 +- .../strategy/ServiceRoleStrategyContext.java | 38 +- .../api/strategy/TSHandlerStrategy.java | 24 +- .../api/strategy/TrinoHandlerStrategy.java | 25 +- .../api/strategy/ZKFCHandlerStrategy.java | 23 +- .../api/strategy/ZkServerHandlerStrategy.java | 50 +- .../com/datasophon/api/utils/CheckUtils.java | 30 +- .../com/datasophon/api/utils/CommonUtils.java | 8 +- .../api/utils/ExecuteShellScriptUtils.java | 19 +- .../com/datasophon/api/utils/HadoopUtils.java | 12 +- .../com/datasophon/api/utils/HttpUtils.java | 10 +- .../api/utils/MessageResolverUtils.java | 13 +- .../com/datasophon/api/utils/MinaUtils.java | 16 +- .../datasophon/api/utils/PackageUtils.java | 6 +- .../datasophon/api/utils/ProcessUtils.java | 254 +++++---- .../datasophon/api/utils/SecurityUtils.java | 18 +- .../datasophon/api/utils/ServletUtils.java | 24 +- .../com/datasophon/api/utils/SpringTool.java | 10 +- .../worker/WorkerApplicationServer.java | 101 ++-- .../worker/actor/AlertConfigActor.java | 2 +- .../worker/actor/CheckServiceStatusActor.java | 4 +- .../worker/actor/ConfigureServiceActor.java | 11 +- .../worker/actor/ExecuteCmdActor.java | 2 +- .../worker/actor/FileOperateActor.java | 2 +- .../worker/actor/InstallServiceActor.java | 26 +- .../worker/actor/KerberosActor.java | 6 +- .../com/datasophon/worker/actor/LogActor.java | 19 +- .../datasophon/worker/actor/NMStateActor.java | 2 +- .../datasophon/worker/actor/PingActor.java | 8 +- .../datasophon/worker/actor/RMStateActor.java | 2 +- .../worker/actor/RemoteEventActor.java | 4 +- .../worker/actor/RestartServiceActor.java | 2 +- .../worker/actor/StartServiceActor.java | 10 +- .../worker/actor/StopServiceActor.java | 8 +- .../worker/actor/SupervisorFunction.java | 2 +- .../worker/actor/UnixGroupActor.java | 4 +- .../worker/actor/UnixUserActor.java | 4 +- .../datasophon/worker/actor/WorkerActor.java | 33 +- .../handler/ConfigureServiceHandler.java | 77 +-- .../worker/handler/InstallServiceHandler.java | 122 +++-- .../worker/handler/ServiceHandler.java | 39 +- .../worker/log/TaskLogDiscriminator.java | 27 +- .../datasophon/worker/log/TaskLogFilter.java | 16 +- .../strategy/AbstractHandlerStrategy.java | 13 +- .../worker/strategy/BEHandlerStrategy.java | 19 +- .../strategy/DSMasterHandlerStrategy.java | 43 +- .../strategy/DataNodeHandlerStrategy.java | 15 +- .../worker/strategy/FEHandlerStrategy.java | 22 +- .../strategy/FEObserverHandlerStrategy.java | 16 +- .../worker/strategy/FlinkHandlerStrategy.java | 17 +- .../worker/strategy/HbaseHandlerStrategy.java | 11 +- .../HistoryServerHandlerStrategy.java | 11 +- .../strategy/HiveServer2HandlerStrategy.java | 17 +- .../strategy/JournalNodeHandlerStrategy.java | 13 +- .../strategy/KAdminHandlerStrategy.java | 8 +- .../worker/strategy/KafkaHandlerStrategy.java | 11 +- .../strategy/Krb5KdcHandlerStrategy.java | 8 +- .../strategy/KyuubiServerHandlerStrategy.java | 80 +-- .../strategy/NameNodeHandlerStrategy.java | 14 +- .../strategy/NodeManagerHandlerStrategy.java | 11 +- .../strategy/RangerAdminHandlerStrategy.java | 15 +- .../ResourceManagerHandlerStrategy.java | 11 +- .../worker/strategy/ServiceRoleStrategy.java | 2 +- .../strategy/ServiceRoleStrategyContext.java | 19 +- .../strategy/TezServerHandlerStrategy.java | 19 +- .../worker/strategy/ZKFCHandlerStrategy.java | 6 +- .../strategy/ZkServerHandlerStrategy.java | 13 +- .../strategy/resource/AppendLineStrategy.java | 20 +- .../strategy/resource/DownloadStrategy.java | 28 +- .../strategy/resource/EmptyStrategy.java | 5 +- .../strategy/resource/LinkStrategy.java | 16 +- .../strategy/resource/ReplaceStrategy.java | 24 +- .../strategy/resource/ResourceStrategy.java | 14 +- .../strategy/resource/ShellStrategy.java | 15 +- .../datasophon/worker/utils/ActorUtils.java | 8 +- .../datasophon/worker/utils/FileUtils.java | 4 +- .../worker/utils/FreemakerUtils.java | 41 +- .../worker/utils/KerberosUtils.java | 14 +- .../worker/utils/TaskConstants.java | 48 +- .../datasophon/worker/utils/UnixUtils.java | 32 +- .../handler/ConfigureServiceHandlerTest.java | 2 +- .../handler/InstallServiceHandlerTest.java | 2 +- .../worker/test/FreemarkerTest.java | 28 +- .../worker/test/MutilTemplateFileTest.java | 2 +- docs/zh/ApacheKyuubi.md | 7 +- ...36\345\212\240\347\224\250\346\210\267.md" | 4 - ...hive on spark \346\250\241\345\274\217.md" | 21 +- ...atasophon\351\233\206\346\210\220Dinky.md" | 4 - ...atasophon\351\233\206\346\210\220Flume.md" | 14 + ...atasophon\351\233\206\346\210\220Minio.md" | 30 + ...asophon\351\233\206\346\210\220alluxio.md" | 22 +- ...phon\351\233\206\346\210\220clickhouse.md" | 23 +- ...hon\351\233\206\346\210\220hbase-2.5.6.md" | 32 +- ...sophon\351\233\206\346\210\220openldap.md" | 40 ++ ...tasophon\351\233\206\346\210\220paimon.md" | 32 +- ...tasophon\351\233\206\346\210\220presto.md" | 82 ++- ...atasophon\351\233\206\346\210\220redis.md" | 32 ++ ...ophon\351\233\206\346\210\220seatunnel.md" | 20 +- ...sophon\351\233\206\346\210\220zeppelin.md" | 18 + ....8\345\256\211\350\243\205\345\214\205.md" | 20 +- ....1\345\256\211\350\243\205\345\214\205.md" | 36 +- ...72\247flink1.15\345\210\260flink1.16.2.md" | 17 + ...7\347\272\247spark3.1\345\210\2603.2.2.md" | 18 + pom.xml | 217 +++++--- style/checkstyle-suppressions.xml | 20 +- style/checkstyle.xml | 516 ++++++++++++------ style/spotless_datasophon_formatter.xml | 58 +- 510 files changed, 6749 insertions(+), 5453 deletions(-) diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml index e972ab23..99ae42c9 100644 --- a/.github/workflows/maven.yaml +++ b/.github/workflows/maven.yaml @@ -34,12 +34,13 @@ jobs: key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- -# - name: Check Style -# run: | -# ./mvnw -T 2C -B --no-snapshot-updates clean checkstyle:check + - name: Check Code Style + run: | + ./mvnw -T 2C -B --no-snapshot-updates clean checkstyle:check - name: Build and Package run: | - ./mvnw -Pgoogle-mirror -B clean install \ - -Dmaven.test.skip=true \ - --no-snapshot-updates \ - -pl !datasophon-ui,!datasophon-api,!datasophon-service -am + ./mvnw -Pgoogle-mirror -B clean package \ + -Dmaven.test.skip=true \ + -Dspotless.check.skip=true \ + --no-snapshot-updates \ + -pl !datasophon-ui,!datasophon-api,!datasophon-service -am diff --git a/datasophon-api/pom.xml b/datasophon-api/pom.xml index 54751c07..e38e9164 100644 --- a/datasophon-api/pom.xml +++ b/datasophon-api/pom.xml @@ -31,6 +31,10 @@ 8 + + cn.hutool + hutool-all + com.datasophon datasophon-service @@ -49,7 +53,8 @@ src/main/resources - front/** + front/** + @@ -72,7 +77,8 @@ ${project.basedir}/src/main/resources - front/** + front/** + diff --git a/datasophon-api/src/main/java/com/datasophon/api/DataSophonApplicationServer.java b/datasophon-api/src/main/java/com/datasophon/api/DataSophonApplicationServer.java index d34958a7..efbff105 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/DataSophonApplicationServer.java +++ b/datasophon-api/src/main/java/com/datasophon/api/DataSophonApplicationServer.java @@ -17,10 +17,16 @@ package com.datasophon.api; -import cn.hutool.extra.spring.EnableSpringUtil; import com.datasophon.api.master.ActorUtils; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.security.NoSuchAlgorithmException; + +import javax.annotation.PostConstruct; + import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -28,10 +34,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; -import javax.annotation.PostConstruct; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.security.NoSuchAlgorithmException; +import cn.hutool.extra.spring.EnableSpringUtil; @SpringBootApplication @ServletComponentScan @@ -39,22 +42,22 @@ @MapperScan("com.datasophon.dao") @EnableSpringUtil public class DataSophonApplicationServer extends SpringBootServletInitializer { - + public static void main(String[] args) { SpringApplication.run(DataSophonApplicationServer.class, args); - // add shutdown hook, close and shutdown resources - Runtime.getRuntime().addShutdownHook(new Thread(() -> { + // add shutdown hook, close and shutdown resources + Runtime.getRuntime().addShutdownHook(new Thread(() -> { shutdown(); })); } - + @PostConstruct public void run() throws UnknownHostException, NoSuchAlgorithmException { String hostName = InetAddress.getLocalHost().getHostName(); CacheUtils.put(Constants.HOSTNAME, hostName); ActorUtils.init(); } - + /** * Master 关闭时调用 */ diff --git a/datasophon-api/src/main/java/com/datasophon/api/configuration/AppConfiguration.java b/datasophon-api/src/main/java/com/datasophon/api/configuration/AppConfiguration.java index 436867ee..a603bccf 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/configuration/AppConfiguration.java +++ b/datasophon-api/src/main/java/com/datasophon/api/configuration/AppConfiguration.java @@ -41,12 +41,12 @@ */ @Configuration public class AppConfiguration implements WebMvcConfigurer { - + public static final String LOGIN_INTERCEPTOR_PATH_PATTERN = "/**/*"; public static final String LOGIN_PATH_PATTERN = "/login"; public static final String PATH_PATTERN = "/**"; public static final String LOCALE_LANGUAGE_COOKIE = "language"; - + @Bean public CorsFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); @@ -57,12 +57,12 @@ public CorsFilter corsFilter() { configSource.registerCorsConfiguration(PATH_PATTERN, config); return new CorsFilter(configSource); } - + @Bean public LoginHandlerInterceptor loginInterceptor() { return new LoginHandlerInterceptor(); } - + /** * Cookie * @return local resolver @@ -77,17 +77,17 @@ public LocaleResolver localeResolver() { localeResolver.setLanguageTagCompliant(false); return localeResolver; } - + @Bean public LocaleChangeInterceptor localeChangeInterceptor() { return new LocaleChangeInterceptor(); } - + @Bean public UserPermissionHandler userPermissionHandler() { return new UserPermissionHandler(); } - + @Override public void addInterceptors(InterceptorRegistry registry) { // i18n @@ -104,7 +104,7 @@ public void addInterceptors(InterceptorRegistry registry) { "/", "/static/**"); } - + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**") @@ -114,13 +114,13 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); registry.addResourceHandler("/ui/**").addResourceLocations("file:ui/"); } - + @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/ui/").setViewName("forward:/ui/index.html"); registry.addViewController("/").setViewName("index"); } - + /** * Turn off suffix-based content negotiation * @@ -130,5 +130,5 @@ public void addViewControllers(ViewControllerRegistry registry) { public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/configuration/ConfigPropertiesExtend.java b/datasophon-api/src/main/java/com/datasophon/api/configuration/ConfigPropertiesExtend.java index 7f8ea718..6b4c48bd 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/configuration/ConfigPropertiesExtend.java +++ b/datasophon-api/src/main/java/com/datasophon/api/configuration/ConfigPropertiesExtend.java @@ -1,8 +1,21 @@ package com.datasophon.api.configuration; import com.datasophon.common.utils.FileUtils; -import lombok.extern.slf4j.Slf4j; + import org.apache.commons.lang3.StringUtils; + +import java.io.File; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import lombok.extern.slf4j.Slf4j; + import org.springframework.boot.SpringApplication; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.boot.env.YamlPropertySourceLoader; @@ -13,18 +26,13 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.util.CollectionUtils; -import java.io.File; -import java.io.InputStream; -import java.nio.file.Files; -import java.util.*; - @Slf4j public class ConfigPropertiesExtend implements EnvironmentPostProcessor { - + private static final String CONFIG_HOME = "conf/datasophon.conf"; - + private static final String DEFAULT_APPLICATION_CONFIG = "conf/profiles/application-config.yml"; - + @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { MutablePropertySources propertySources = environment.getPropertySources(); @@ -32,14 +40,15 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp checkProfile(environment); propertySources.addFirst(new PropertiesPropertySource("datasophonConfig", properties)); } - + private Properties loadCustomProperties() { Properties properties = new Properties(); File file = new File(FileUtils.concatPath(System.getProperty("user.dir"), CONFIG_HOME)); try (InputStream inputStream = Files.newInputStream(file.toPath())) { properties.load(inputStream); } catch (Exception e) { - System.err.println("Failed to load the datart configuration (config/datart.conf), use application-config.yml"); + System.err.println( + "Failed to load the datart configuration (config/datart.conf), use application-config.yml"); return new Properties(); } List removeKeys = new ArrayList<>(); @@ -55,7 +64,7 @@ private Properties loadCustomProperties() { } return properties; } - + private void checkProfile(ConfigurableEnvironment environment) { List activeProfiles = Arrays.asList(environment.getActiveProfiles()); if (!activeProfiles.isEmpty() && !Collections.singletonList("config").containsAll(activeProfiles)) { @@ -63,7 +72,8 @@ private void checkProfile(ConfigurableEnvironment environment) { return; } try { - List> propertySources = new YamlPropertySourceLoader().load(DEFAULT_APPLICATION_CONFIG, new FileSystemResource(DEFAULT_APPLICATION_CONFIG)); + List> propertySources = new YamlPropertySourceLoader().load(DEFAULT_APPLICATION_CONFIG, + new FileSystemResource(DEFAULT_APPLICATION_CONFIG)); if (CollectionUtils.isEmpty(propertySources)) { System.err.println("Default config application-config not found "); } diff --git a/datasophon-api/src/main/java/com/datasophon/api/configuration/DatabaseMigrationAware.java b/datasophon-api/src/main/java/com/datasophon/api/configuration/DatabaseMigrationAware.java index c5784a38..2eb04ca7 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/configuration/DatabaseMigrationAware.java +++ b/datasophon-api/src/main/java/com/datasophon/api/configuration/DatabaseMigrationAware.java @@ -20,7 +20,9 @@ package com.datasophon.api.configuration; import com.datasophon.api.migration.DatabaseMigration; + import lombok.extern.slf4j.Slf4j; + import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -30,7 +32,7 @@ @Slf4j @Component public class DatabaseMigrationAware implements ApplicationContextAware, Ordered { - + @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { String migrationEnable = applicationContext.getEnvironment().getProperty("datasophon.migration.enable"); @@ -45,10 +47,10 @@ public void setApplicationContext(ApplicationContext applicationContext) throws throw new RuntimeException(e); } } - + @Override public int getOrder() { return 0; } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/AlertGroupController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/AlertGroupController.java index 4570dd53..b9875b27 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/AlertGroupController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/AlertGroupController.java @@ -24,7 +24,9 @@ import com.datasophon.dao.entity.AlertGroupEntity; import com.datasophon.dao.entity.ClusterAlertQuota; -import java.util.*; +import java.util.Arrays; +import java.util.Date; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; @@ -35,13 +37,13 @@ @RestController @RequestMapping("alert/group") public class AlertGroupController { - + @Autowired private AlertGroupService alertGroupService; - + @Autowired private ClusterAlertQuotaService alertQuotaService; - + /** * 列表 */ @@ -49,17 +51,17 @@ public class AlertGroupController { public Result list(Integer clusterId, String alertGroupName, Integer page, Integer pageSize) { return alertGroupService.getAlertGroupList(clusterId, alertGroupName, page, pageSize); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { AlertGroupEntity alertGroup = alertGroupService.getById(id); - + return Result.success().put("alertGroup", alertGroup); } - + /** * 保存 */ @@ -68,23 +70,23 @@ public Result save(@RequestBody AlertGroupEntity alertGroup) { alertGroup.setCreateTime(new Date()); return alertGroupService.saveAlertGroup(alertGroup); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody AlertGroupEntity alertGroup) { alertGroupService.updateById(alertGroup); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { - + // 校验是否绑定告警指标 List list = alertQuotaService.lambdaQuery().in(ClusterAlertQuota::getAlertGroupId, ids).list(); @@ -92,8 +94,8 @@ public Result delete(@RequestBody Integer[] ids) { return Result.error(Status.ALERT_GROUP_TIPS_ONE.getMsg()); } alertGroupService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertGroupMapController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertGroupMapController.java index 74130698..d0623877 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertGroupMapController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertGroupMapController.java @@ -32,58 +32,58 @@ @RestController @RequestMapping("cluster/alert/group/map") public class ClusterAlertGroupMapController { - + @Autowired private ClusterAlertGroupMapService clusterAlertGroupMapService; - + /** * 列表 */ @RequestMapping("/list") public Result list() { - + return Result.success(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterAlertGroupMap clusterAlertGroupMap = clusterAlertGroupMapService.getById(id); - + return Result.success().put("clusterAlertGroupMap", clusterAlertGroupMap); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterAlertGroupMap clusterAlertGroupMap) { clusterAlertGroupMapService.save(clusterAlertGroupMap); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterAlertGroupMap clusterAlertGroupMap) { - + clusterAlertGroupMapService.updateById(clusterAlertGroupMap); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterAlertGroupMapService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertHistoryController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertHistoryController.java index e1d69615..8355623b 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertHistoryController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertHistoryController.java @@ -32,10 +32,10 @@ @RestController @RequestMapping("cluster/alert/history") public class ClusterAlertHistoryController { - + @Autowired private ClusterAlertHistoryService clusterAlertHistoryService; - + /** * 列表 */ @@ -43,7 +43,7 @@ public class ClusterAlertHistoryController { public Result getAlertList(Integer serviceInstanceId) { return clusterAlertHistoryService.getAlertList(serviceInstanceId); } - + /** * 列表 */ @@ -51,17 +51,17 @@ public Result getAlertList(Integer serviceInstanceId) { public Result getAllAlertList(Integer clusterId, Integer page, Integer pageSize) { return clusterAlertHistoryService.getAllAlertList(clusterId, page, pageSize); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterAlertHistory clusterAlertHistory = clusterAlertHistoryService.getById(id); - + return Result.success().put("clusterAlertHistory", clusterAlertHistory); } - + /** * 保存 */ @@ -70,26 +70,26 @@ public Result save(@RequestBody String alertMessage) { clusterAlertHistoryService.saveAlertHistory(alertMessage); return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterAlertHistory clusterAlertHistory) { - + clusterAlertHistoryService.updateById(clusterAlertHistory); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterAlertHistoryService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertQuotaController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertQuotaController.java index 9d71ea3f..5a23de7d 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertQuotaController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterAlertQuotaController.java @@ -21,21 +21,21 @@ import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterAlertQuota; import com.datasophon.dao.enums.QuotaState; + +import java.util.Arrays; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Arrays; -import java.util.List; - @RestController @RequestMapping("cluster/alert/quota") public class ClusterAlertQuotaController { - + @Autowired private ClusterAlertQuotaService clusterAlertQuotaService; - + /** * list alert quota */ @@ -43,7 +43,7 @@ public class ClusterAlertQuotaController { public Result info(Integer clusterId, Integer alertGroupId, String quotaName, Integer page, Integer pageSize) { return clusterAlertQuotaService.getAlertQuotaList(clusterId, alertGroupId, quotaName, page, pageSize); } - + /** * enable alert quota */ @@ -52,7 +52,7 @@ public Result start(Integer clusterId, String alertQuotaIds) { clusterAlertQuotaService.start(clusterId, alertQuotaIds); return Result.success(); } - + /** * disable alert quota */ @@ -61,17 +61,17 @@ public Result stop(Integer clusterId, String alertQuotaIds) { clusterAlertQuotaService.stop(clusterId, alertQuotaIds); return Result.success(); } - + /** * save alert quota */ @RequestMapping("/save") public Result save(@RequestBody ClusterAlertQuota clusterAlertQuota) { - + clusterAlertQuotaService.saveAlertQuota(clusterAlertQuota); return Result.success(); } - + /** * update alert quota */ @@ -79,18 +79,18 @@ public Result save(@RequestBody ClusterAlertQuota clusterAlertQuota) { public Result update(@RequestBody ClusterAlertQuota clusterAlertQuota) { clusterAlertQuota.setQuotaState(QuotaState.WAIT_TO_UPDATE); clusterAlertQuotaService.updateById(clusterAlertQuota); - + return Result.success(); } - + /** * delete alert quota */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterAlertQuotaService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterGroupController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterGroupController.java index d6a0b9cd..70d8c7a5 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterGroupController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterGroupController.java @@ -29,29 +29,29 @@ @RestController @RequestMapping("cluster/group") public class ClusterGroupController { - + @Autowired private ClusterGroupService clusterGroupService; - + /** * 列表 */ @RequestMapping("/list") public Result list(String groupName, Integer clusterId, Integer page, Integer pageSize) { - + return clusterGroupService.listPage(groupName, clusterId, page, pageSize); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterGroup clusterGroup = clusterGroupService.getById(id); - + return Result.success().put("clusterGroup", clusterGroup); } - + /** * 保存 */ @@ -59,7 +59,7 @@ public Result info(@PathVariable("id") Integer id) { public Result save(Integer clusterId, String groupName) { return clusterGroupService.saveClusterGroup(clusterId, groupName); } - + /** * 删除用户组 */ @@ -67,16 +67,16 @@ public Result save(Integer clusterId, String groupName) { public Result delete(Integer id) { return clusterGroupService.deleteUserGroup(id); } - + /** * 刷新用户组到主机 */ @RequestMapping("/refreshUserGroupToHost") public Result refreshUserGroupToHost(Integer clusterId) { - + clusterGroupService.refreshUserGroupToHost(clusterId); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterHostController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterHostController.java index 274f6bd2..77e43d4d 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterHostController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterHostController.java @@ -22,10 +22,12 @@ import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterHostDO; +import org.apache.commons.lang3.StringUtils; + import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -38,10 +40,10 @@ @RestController @RequestMapping("api/cluster/host") public class ClusterHostController { - + @Autowired private ClusterHostService clusterHostService; - + /** * 查询集群所有主机 */ @@ -53,7 +55,7 @@ public Result all(Integer clusterId) { .orderByAsc(Constants.HOSTNAME)); return Result.success(list); } - + /** * 查询集群所有主机 */ @@ -62,63 +64,63 @@ public Result list(Integer clusterId, String hostname, String ip, String cpuArch String orderField, String orderType, Integer page, Integer pageSize) { return clusterHostService.listByPage(clusterId, hostname, ip, cpuArchitecture, hostState, orderField, orderType, page, pageSize); - + } - + @RequestMapping("/getRoleListByHostname") public Result getRoleListByHostname(Integer clusterId, String hostname) { return clusterHostService.getRoleListByHostname(clusterId, hostname); - + } - + @RequestMapping("/getRack") public Result getRack(Integer clusterId) { return clusterHostService.getRack(clusterId); - + } - + @RequestMapping("/assignRack") public Result assignRack(Integer clusterId, String rack, String hostIds) { return clusterHostService.assignRack(clusterId, rack, hostIds); - + } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterHostDO clusterHost = clusterHostService.getById(id); - + return Result.success().put(Constants.DATA, clusterHost); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterHostDO clusterHost) { clusterHostService.save(clusterHost); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterHostDO clusterHost) { clusterHostService.updateById(clusterHost); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(String hostIds) { - if(StringUtils.isBlank(hostIds)) { + if (StringUtils.isBlank(hostIds)) { return Result.error("请选择移除的主机!"); } try { @@ -128,5 +130,5 @@ public Result delete(String hostIds) { return Result.error("移除主机异常, Cause: " + e.getMessage()); } } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterInfoController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterInfoController.java index a4e78bb0..9869100a 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterInfoController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterInfoController.java @@ -34,10 +34,10 @@ @RestController @RequestMapping("api/cluster") public class ClusterInfoController { - + @Autowired private ClusterInfoService clusterInfoService; - + /** * 列表 */ @@ -45,6 +45,7 @@ public class ClusterInfoController { public Result list() { return clusterInfoService.getClusterList(); } + /** * 配置好的集群列表 */ @@ -52,17 +53,17 @@ public Result list() { public Result runningClusterList() { return clusterInfoService.runningClusterList(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(id); - + return Result.success().put(Constants.DATA, clusterInfo); } - + /** * 保存 */ @@ -71,13 +72,13 @@ public Result info(@PathVariable("id") Integer id) { public Result save(@RequestBody ClusterInfoEntity clusterInfo) { return clusterInfoService.saveCluster(clusterInfo); } - + @RequestMapping("/updateClusterState") public Result updateClusterState(Integer clusterId, Integer clusterState) { - + return clusterInfoService.updateClusterState(clusterId, clusterState); } - + /** * 修改 */ @@ -85,9 +86,9 @@ public Result updateClusterState(Integer clusterId, Integer clusterState) { @UserPermission public Result update(@RequestBody ClusterInfoEntity clusterInfo) { return clusterInfoService.updateCluster(clusterInfo); - + } - + /** * 删除 */ @@ -95,8 +96,8 @@ public Result update(@RequestBody ClusterInfoEntity clusterInfo) { @UserPermission public Result delete(@RequestBody Integer[] ids) { clusterInfoService.deleteCluster(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterKerberosController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterKerberosController.java index 82e24559..b560d705 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterKerberosController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterKerberosController.java @@ -25,16 +25,20 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController @RequestMapping("cluster/kerberos") public class ClusterKerberosController { - + @Autowired private ClusterKerberosService kerberosService; - + /** * download keytab */ @@ -43,7 +47,7 @@ public void downloadKeytab(Integer clusterId, String principal, String keytabNam HttpServletResponse response) throws IOException { kerberosService.downloadKeytab(clusterId, principal, keytabName, hostname, response); } - + /** * upload keytab */ @@ -52,5 +56,5 @@ public void uploadFile(@RequestParam(value = "file") MultipartFile file, String String keytabFileName) throws IOException { kerberosService.uploadKeytab(file, hostname, keytabFileName); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterNodeLabelController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterNodeLabelController.java index 58dba8b1..7ab95748 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterNodeLabelController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterNodeLabelController.java @@ -30,10 +30,10 @@ @RestController @RequestMapping("cluster/node/label") public class ClusterNodeLabelController { - + @Autowired private ClusterNodeLabelService nodeLabelService; - + /** * save node label */ @@ -42,7 +42,7 @@ public Result list(Integer clusterId) { List list = nodeLabelService.queryClusterNodeLabel(clusterId); return Result.success(list); } - + /** * save node label */ @@ -50,7 +50,7 @@ public Result list(Integer clusterId) { public Result save(Integer clusterId, String nodeLabel) { return nodeLabelService.saveNodeLabel(clusterId, nodeLabel); } - + /** * delete node label */ @@ -58,7 +58,7 @@ public Result save(Integer clusterId, String nodeLabel) { public Result delete(Integer nodeLabelId) { return nodeLabelService.deleteNodeLabel(nodeLabelId); } - + /** * assign node label */ diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterQueueCapacityController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterQueueCapacityController.java index 1d4c6feb..9d51266c 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterQueueCapacityController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterQueueCapacityController.java @@ -30,61 +30,61 @@ @RestController @RequestMapping("cluster/queue/capacity") public class ClusterQueueCapacityController { - + @Autowired private ClusterQueueCapacityService clusterQueueCapacityService; - + /** * 列表 */ @RequestMapping("/list") public Result list(Integer clusterId) { - + return clusterQueueCapacityService.listCapacityQueue(clusterId); - + } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterQueueCapacity clusterQueueCapacity = clusterQueueCapacityService.getById(id); - + return Result.success().put("clusterQueueCapacity", clusterQueueCapacity); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterQueueCapacity clusterQueueCapacity) { clusterQueueCapacityService.save(clusterQueueCapacity); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterQueueCapacity clusterQueueCapacity) { - + clusterQueueCapacityService.updateById(clusterQueueCapacity); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(Integer id) { clusterQueueCapacityService.removeById(id); - + return Result.success(); } - + /** * 删除 */ diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRackController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRackController.java index 6130ff48..ebe76ef5 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRackController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRackController.java @@ -31,10 +31,10 @@ @RestController @RequestMapping("cluster/rack") public class ClusterRackController { - + @Autowired private ClusterRackService clusterRackService; - + /** * 列表 */ @@ -43,17 +43,17 @@ public Result list(Integer clusterId) { List list = clusterRackService.queryClusterRack(clusterId); return Result.success(list); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterRack clusterRack = clusterRackService.getById(id); - + return Result.success().put("clusterRack", clusterRack); } - + /** * 保存 */ @@ -62,7 +62,7 @@ public Result save(Integer clusterId, String rack) { clusterRackService.saveRack(clusterId, rack); return Result.success(); } - + /** * 删除 */ @@ -70,5 +70,5 @@ public Result save(Integer clusterId, String rack) { public Result delete(Integer clusterId, Integer rackId) { return clusterRackService.deleteRack(rackId); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRoleUserController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRoleUserController.java index d8e4a047..4b958b83 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRoleUserController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterRoleUserController.java @@ -35,29 +35,29 @@ @RestController @RequestMapping("api/cluster/user") public class ClusterRoleUserController { - + @Autowired private ClusterRoleUserService clusterRoleUserService; - + /** * 列表 */ @RequestMapping("/list") public Result list(@RequestParam Map params) { - + return Result.success(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterRoleUserEntity clusterRoleUser = clusterRoleUserService.getById(id); - + return Result.success().put("clusterRoleUser", clusterRoleUser); } - + /** * 保存 */ @@ -66,25 +66,25 @@ public Result info(@PathVariable("id") Integer id) { public Result saveClusterManager(Integer clusterId, String userIds) { return clusterRoleUserService.saveClusterManager(clusterId, userIds); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterRoleUserEntity clusterRoleUser) { clusterRoleUserService.updateById(clusterRoleUser); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterRoleUserService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandController.java index 809b7003..561c86fb 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandController.java @@ -24,7 +24,7 @@ import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceCommandEntity; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.Arrays; import java.util.List; @@ -40,10 +40,10 @@ @RestController @RequestMapping("api/cluster/service/command") public class ClusterServiceCommandController { - + @Autowired private ClusterServiceCommandService clusterServiceCommandService; - + /** * 查询集群服务指令列表 */ @@ -51,7 +51,7 @@ public class ClusterServiceCommandController { public Result list(Integer clusterId, Integer page, Integer pageSize) { return clusterServiceCommandService.getServiceCommandlist(clusterId, page, pageSize); } - + /** * 生成服务安装操作指令 */ @@ -62,7 +62,7 @@ public Result generateCommand(Integer clusterId, String commandType, String serv List list = Arrays.asList(serviceNames.split(",")); return clusterServiceCommandService.generateCommand(clusterId, command, list); } - + /** * 生成服务实例操作指令 */ @@ -76,9 +76,9 @@ public Result generateServiceCommand(Integer clusterId, String commandType, Stri } else { return Result.error(Status.NO_SERVICE_EXECUTE.getMsg()); } - + } - + /** * 生成服务角色实例操作指令 */ @@ -89,9 +89,9 @@ public Result generateServiceRoleCommand(Integer clusterId, String commandType, CommandType command = EnumUtil.fromString(CommandType.class, commandType); List ids = Arrays.asList(serviceRoleInstancesIds.split(",")); return clusterServiceCommandService.generateServiceRoleCommand(clusterId, command, serviceInstanceId, ids); - + } - + /** * 启动执行指令 */ @@ -101,51 +101,51 @@ public Result startExecuteCommand(Integer clusterId, String commandType, String clusterServiceCommandService.startExecuteCommand(clusterId, commandType, commandIds); return Result.success(); } - + @RequestMapping("/cancelCommand") public Result cancelCommand(String commandId) { clusterServiceCommandService.cancelCommand(commandId); return Result.success(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterServiceCommandEntity clusterServiceCommand = clusterServiceCommandService.getById(id); - + return Result.success().put("clusterServiceCommand", clusterServiceCommand); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceCommandEntity clusterServiceCommand) { clusterServiceCommandService.save(clusterServiceCommand); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceCommandEntity clusterServiceCommand) { clusterServiceCommandService.updateById(clusterServiceCommand); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterServiceCommandService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostCommandController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostCommandController.java index a1739a22..b8c4f252 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostCommandController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostCommandController.java @@ -32,24 +32,24 @@ @RestController @RequestMapping("api/cluster/service/command/host/command") public class ClusterServiceCommandHostCommandController { - + @Autowired private ClusterServiceCommandHostCommandService clusterServiceCommandHostCommandService; - + /** * 列表 */ @RequestMapping("/list") public Result list(String hostname, String commandHostId, Integer page, Integer pageSize) { - + return clusterServiceCommandHostCommandService.getHostCommandList(hostname, commandHostId, page, pageSize); } - + @RequestMapping("/getHostCommandLog") public Result getHostCommandLog(Integer clusterId, String hostCommandId) throws Exception { return clusterServiceCommandHostCommandService.getHostCommandLog(clusterId, hostCommandId); } - + /** * 信息 */ @@ -57,38 +57,38 @@ public Result getHostCommandLog(Integer clusterId, String hostCommandId) throws public Result info(@PathVariable("id") Integer id) { ClusterServiceCommandHostCommandEntity clusterServiceCommandHostCommand = clusterServiceCommandHostCommandService.getById(id); - + return Result.success().put("clusterServiceCommandHostCommand", clusterServiceCommandHostCommand); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceCommandHostCommandEntity clusterServiceCommandHostCommand) { clusterServiceCommandHostCommandService.save(clusterServiceCommandHostCommand); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceCommandHostCommandEntity clusterServiceCommandHostCommand) { clusterServiceCommandHostCommandService.updateById(clusterServiceCommandHostCommand); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterServiceCommandHostCommandService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostController.java index 63362bc0..13975162 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceCommandHostController.java @@ -32,10 +32,10 @@ @RestController @RequestMapping("api/cluster/service/command/host") public class ClusterServiceCommandHostController { - + @Autowired private ClusterServiceCommandHostService clusterServiceCommandHostService; - + /** * 列表 */ @@ -43,45 +43,45 @@ public class ClusterServiceCommandHostController { public Result list(Integer clusterId, String commandId, Integer page, Integer pageSize) { return clusterServiceCommandHostService.getCommandHostList(clusterId, commandId, page, pageSize); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterServiceCommandHostEntity clusterServiceCommandHost = clusterServiceCommandHostService.getById(id); - + return Result.success().put("clusterServiceCommandHost", clusterServiceCommandHost); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceCommandHostEntity clusterServiceCommandHost) { clusterServiceCommandHostService.save(clusterServiceCommandHost); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceCommandHostEntity clusterServiceCommandHost) { clusterServiceCommandHostService.updateById(clusterServiceCommandHost); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterServiceCommandHostService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceDashboardController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceDashboardController.java index 0a78d876..aad80b16 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceDashboardController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceDashboardController.java @@ -27,17 +27,17 @@ @RestController @RequestMapping("cluster/service/dashboard") public class ClusterServiceDashboardController { - + @Autowired private ClusterServiceDashboardService clusterServiceDashboardService; - + /** * 列表 */ @RequestMapping("/getDashboardUrl") public Result getDashboardUrl(Integer clusterId) { - + return clusterServiceDashboardService.getDashboardUrl(clusterId); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceConfigController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceConfigController.java index 87fc52be..c3e5776d 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceConfigController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceConfigController.java @@ -31,10 +31,10 @@ @RestController @RequestMapping("cluster/service/instance/config") public class ClusterServiceInstanceConfigController { - + @Autowired private ClusterServiceInstanceConfigService clusterServiceInstanceConfigService; - + /** * 列表 */ @@ -42,7 +42,7 @@ public class ClusterServiceInstanceConfigController { public Result getConfigVersion(Integer serviceInstanceId, Integer roleGroupId) { return clusterServiceInstanceConfigService.getConfigVersion(serviceInstanceId, roleGroupId); } - + /** * 信息 */ @@ -52,35 +52,35 @@ public Result info(Integer serviceInstanceId, Integer version, Integer roleGroup return clusterServiceInstanceConfigService.getServiceInstanceConfig(serviceInstanceId, version, roleGroupId, page, pageSize); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceInstanceConfigEntity clusterServiceInstanceConfig) { clusterServiceInstanceConfigService.save(clusterServiceInstanceConfig); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceInstanceConfigEntity clusterServiceInstanceConfig) { clusterServiceInstanceConfigService.updateById(clusterServiceInstanceConfig); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterServiceInstanceConfigService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceController.java index 0b953feb..e8f84493 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceController.java @@ -30,10 +30,10 @@ @RestController @RequestMapping("cluster/service/instance") public class ClusterServiceInstanceController { - + @Autowired private ClusterServiceInstanceService clusterServiceInstanceService; - + /** * 列表 */ @@ -41,7 +41,7 @@ public class ClusterServiceInstanceController { public Result list(Integer clusterId) { return Result.success(clusterServiceInstanceService.listAll(clusterId)); } - + /** * 获取服务角色类型列表 */ @@ -49,7 +49,7 @@ public Result list(Integer clusterId) { public Result getServiceRoleType(Integer serviceInstanceId) { return clusterServiceInstanceService.getServiceRoleType(serviceInstanceId); } - + /** * 获取服务角色类型列表 */ @@ -57,46 +57,46 @@ public Result getServiceRoleType(Integer serviceInstanceId) { public Result configVersionCompare(Integer serviceInstanceId, Integer roleGroupId) { return clusterServiceInstanceService.configVersionCompare(serviceInstanceId, roleGroupId); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterServiceInstanceEntity clusterServiceInstance = clusterServiceInstanceService.getById(id); - + return Result.success().put("clusterServiceInstance", clusterServiceInstance); } - + /** * 信息 */ @RequestMapping("/downloadClientConfig") public Result downloadClientConfig(Integer clusterId, String serviceName) { - + return clusterServiceInstanceService.downloadClientConfig(clusterId, serviceName); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceInstanceEntity clusterServiceInstance) { clusterServiceInstanceService.save(clusterServiceInstance); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceInstanceEntity clusterServiceInstance) { clusterServiceInstanceService.updateById(clusterServiceInstance); - + return Result.success(); } - + /** * 删除 */ @@ -104,5 +104,5 @@ public Result update(@RequestBody ClusterServiceInstanceEntity clusterServiceIns public Result delete(Integer serviceInstanceId) { return clusterServiceInstanceService.delServiceInstance(serviceInstanceId); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceRoleGroupController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceRoleGroupController.java index 0235dd23..27661c09 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceRoleGroupController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceInstanceRoleGroupController.java @@ -34,10 +34,10 @@ @RestController @RequestMapping("cluster/service/instance/role/group") public class ClusterServiceInstanceRoleGroupController { - + @Autowired private ClusterServiceInstanceRoleGroupService clusterServiceInstanceRoleGroupService; - + /** * 列表 */ @@ -48,7 +48,7 @@ public Result list(Integer serviceInstanceId) { .eq(Constants.SERVICE_INSTANCE_ID, serviceInstanceId)); return Result.success(list); } - + /** * 信息 */ @@ -56,10 +56,10 @@ public Result list(Integer serviceInstanceId) { public Result info(@PathVariable("id") Integer id) { ClusterServiceInstanceRoleGroup clusterServiceInstanceRoleGroup = clusterServiceInstanceRoleGroupService.getById(id); - + return Result.success().put("clusterServiceInstanceRoleGroup", clusterServiceInstanceRoleGroup); } - + /** * 保存 */ @@ -68,7 +68,7 @@ public Result save(Integer serviceInstanceId, Integer roleGroupId, String roleGr clusterServiceInstanceRoleGroupService.saveRoleGroup(serviceInstanceId, roleGroupId, roleGroupName); return Result.success(); } - + /** * 分配角色组 */ @@ -76,25 +76,25 @@ public Result save(Integer serviceInstanceId, Integer roleGroupId, String roleGr public Result bind(String roleInstanceIds, Integer roleGroupId) { return clusterServiceInstanceRoleGroupService.bind(roleInstanceIds, roleGroupId); } - + /** * 修改 */ @RequestMapping("/rename") public Result update(Integer roleGroupId, String roleGroupName) { - + return clusterServiceInstanceRoleGroupService.rename(roleGroupId, roleGroupName); - + } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(Integer roleGroupId) { // clusterServiceInstanceRoleGroupService.removeByIds(Arrays.asList(ids)); - + return clusterServiceInstanceRoleGroupService.deleteRoleGroup(roleGroupId); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleGroupConfigController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleGroupConfigController.java index fff7a954..c7a5404e 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleGroupConfigController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleGroupConfigController.java @@ -32,58 +32,58 @@ @RestController @RequestMapping("cluster/service/role/group/config") public class ClusterServiceRoleGroupConfigController { - + @Autowired private ClusterServiceRoleGroupConfigService clusterServiceRoleGroupConfigService; - + /** * 列表 */ @RequestMapping("/list") public Result list() { - + return Result.success(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterServiceRoleGroupConfig clusterServiceRoleGroupConfig = clusterServiceRoleGroupConfigService.getById(id); - + return Result.success().put("clusterServiceRoleGroupConfig", clusterServiceRoleGroupConfig); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceRoleGroupConfig clusterServiceRoleGroupConfig) { clusterServiceRoleGroupConfigService.save(clusterServiceRoleGroupConfig); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceRoleGroupConfig clusterServiceRoleGroupConfig) { - + clusterServiceRoleGroupConfigService.updateById(clusterServiceRoleGroupConfig); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterServiceRoleGroupConfigService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceConfigController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceConfigController.java index 2bde86f1..7ce1fcd3 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceConfigController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceConfigController.java @@ -34,19 +34,19 @@ @RestController @RequestMapping("api/clusterserviceroleinstanceconfig") public class ClusterServiceRoleInstanceConfigController { - + @Autowired private ClusterServiceRoleInstanceConfigService clusterServiceRoleInstanceConfigService; - + /** * 列表 */ @RequestMapping("/list") public Result list(@RequestParam Map params) { - + return Result.success(); } - + /** * 信息 */ @@ -54,38 +54,38 @@ public Result list(@RequestParam Map params) { public Result info(@PathVariable("id") Integer id) { ClusterServiceRoleInstanceConfigEntity clusterServiceRoleInstanceConfig = clusterServiceRoleInstanceConfigService.getById(id); - + return Result.success().put("clusterServiceRoleInstanceConfig", clusterServiceRoleInstanceConfig); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceRoleInstanceConfigEntity clusterServiceRoleInstanceConfig) { clusterServiceRoleInstanceConfigService.save(clusterServiceRoleInstanceConfig); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceRoleInstanceConfigEntity clusterServiceRoleInstanceConfig) { clusterServiceRoleInstanceConfigService.updateById(clusterServiceRoleInstanceConfig); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterServiceRoleInstanceConfigService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceController.java index 29848b8c..a6e964ef 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceController.java @@ -32,10 +32,10 @@ @RestController @RequestMapping("cluster/service/role/instance") public class ClusterServiceRoleInstanceController { - + @Autowired private ClusterServiceRoleInstanceService clusterServiceRoleInstanceService; - + /** * 列表 */ @@ -45,7 +45,7 @@ public Result list(Integer serviceInstanceId, String hostname, Integer serviceRo return clusterServiceRoleInstanceService.listAll(serviceInstanceId, hostname, serviceRoleState, serviceRoleName, roleGroupId, page, pageSize); } - + /** * 信息 */ @@ -53,7 +53,7 @@ public Result list(Integer serviceInstanceId, String hostname, Integer serviceRo public Result getLog(Integer serviceRoleInstanceId) throws Exception { return clusterServiceRoleInstanceService.getLog(serviceRoleInstanceId); } - + /** * 退役 */ @@ -61,7 +61,7 @@ public Result getLog(Integer serviceRoleInstanceId) throws Exception { public Result decommissionNode(String serviceRoleInstanceIds, String serviceName) throws Exception { return clusterServiceRoleInstanceService.decommissionNode(serviceRoleInstanceIds, serviceName); } - + /** * 重启过时服务 */ @@ -69,17 +69,17 @@ public Result decommissionNode(String serviceRoleInstanceIds, String serviceName public Result restartObsoleteService(Integer roleGroupId) throws Exception { return clusterServiceRoleInstanceService.restartObsoleteService(roleGroupId); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceRoleInstanceEntity clusterServiceRoleInstance) { clusterServiceRoleInstanceService.save(clusterServiceRoleInstance); - + return Result.success(); } - + /** * 修改 */ @@ -88,7 +88,7 @@ public Result update(@RequestBody ClusterServiceRoleInstanceEntity clusterServic clusterServiceRoleInstanceService.updateById(clusterServiceRoleInstance); return Result.success(); } - + /** * 删除 */ @@ -97,5 +97,5 @@ public Result delete(String serviceRoleInstancesIds) { List idList = Arrays.asList(serviceRoleInstancesIds.split(",")); return clusterServiceRoleInstanceService.deleteServiceRole(idList); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceWebuisController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceWebuisController.java index 091dda96..3c80aa26 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceWebuisController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterServiceRoleInstanceWebuisController.java @@ -32,19 +32,19 @@ @RestController @RequestMapping("cluster/webuis") public class ClusterServiceRoleInstanceWebuisController { - + @Autowired private ClusterServiceRoleInstanceWebuisService clusterServiceRoleInstanceWebuisService; - + /** * 列表 */ @RequestMapping("/getWebUis") public Result getWebUis(Integer serviceInstanceId) { - + return clusterServiceRoleInstanceWebuisService.getWebUis(serviceInstanceId); } - + /** * 信息 */ @@ -52,39 +52,39 @@ public Result getWebUis(Integer serviceInstanceId) { public Result info(@PathVariable("id") Integer id) { ClusterServiceRoleInstanceWebuis clusterServiceRoleInstanceWebuis = clusterServiceRoleInstanceWebuisService.getById(id); - + return Result.success().put("clusterServiceRoleInstanceWebuis", clusterServiceRoleInstanceWebuis); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterServiceRoleInstanceWebuis clusterServiceRoleInstanceWebuis) { clusterServiceRoleInstanceWebuisService.save(clusterServiceRoleInstanceWebuis); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterServiceRoleInstanceWebuis clusterServiceRoleInstanceWebuis) { - + clusterServiceRoleInstanceWebuisService.updateById(clusterServiceRoleInstanceWebuis); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterServiceRoleInstanceWebuisService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserController.java index f162e9db..ad4ff706 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserController.java @@ -30,49 +30,49 @@ @RestController @RequestMapping("cluster/user") public class ClusterUserController { - + @Autowired private ClusterUserService clusterUserService; - + /** * 列表 */ @RequestMapping("/list") public Result list(Integer clusterId, String username, Integer page, Integer pageSize) { - + return clusterUserService.listPage(clusterId, username, page, pageSize); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterUser clusterUser = clusterUserService.getById(id); - + return Result.success().put("clusterUser", clusterUser); } - + /** * 保存 */ @RequestMapping("/create") public Result save(Integer clusterId, String username, Integer mainGroupId, String otherGroupIds) { - + return clusterUserService.create(clusterId, username, mainGroupId, otherGroupIds); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterUser clusterUser) { - + clusterUserService.updateById(clusterUser); - + return Result.success(); } - + /** * 删除 */ @@ -80,5 +80,5 @@ public Result update(@RequestBody ClusterUser clusterUser) { public Result delete(Integer id) { return clusterUserService.deleteClusterUser(id); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserGroupController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserGroupController.java index 8d18b466..1d337c36 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserGroupController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterUserGroupController.java @@ -31,48 +31,48 @@ @RestController @RequestMapping("api/clusterusergroup") public class ClusterUserGroupController { - + @Autowired private ClusterUserGroupService clusterUserGroupService; - + /** * 列表 */ @RequestMapping("/list") public Result list() { - + return Result.success(); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterUserGroup clusterUserGroup) { clusterUserGroupService.save(clusterUserGroup); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterUserGroup clusterUserGroup) { - + clusterUserGroupService.updateById(clusterUserGroup); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterUserGroupService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnQueueController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnQueueController.java index cd9955ec..4073c0d2 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnQueueController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnQueueController.java @@ -23,7 +23,10 @@ import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterYarnQueue; -import java.util.*; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Objects; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; @@ -36,10 +39,10 @@ @RestController @RequestMapping("cluster/yarn/queue") public class ClusterYarnQueueController { - + @Autowired private ClusterYarnQueueService clusterYarnQueueService; - + /** * 列表 */ @@ -47,7 +50,7 @@ public class ClusterYarnQueueController { public Result list(Integer clusterId, Integer page, Integer pageSize) { return clusterYarnQueueService.listByPage(clusterId, page, pageSize); } - + /** * 刷新队列 */ @@ -55,17 +58,17 @@ public Result list(Integer clusterId, Integer page, Integer pageSize) { public Result refreshQueues(Integer clusterId) throws Exception { return clusterYarnQueueService.refreshQueues(clusterId); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { ClusterYarnQueue clusterYarnQueue = clusterYarnQueueService.getById(id); - + return Result.success().put("clusterYarnQueue", clusterYarnQueue); } - + /** * 保存 */ @@ -78,29 +81,29 @@ public Result save(@RequestBody ClusterYarnQueue clusterYarnQueue) { } clusterYarnQueue.setCreateTime(new Date()); clusterYarnQueueService.save(clusterYarnQueue); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterYarnQueue clusterYarnQueue) { - + clusterYarnQueueService.updateById(clusterYarnQueue); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterYarnQueueService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnSchedulerController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnSchedulerController.java index 1e8db520..2caa0843 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnSchedulerController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ClusterYarnSchedulerController.java @@ -31,58 +31,58 @@ @RestController @RequestMapping("cluster/yarn/scheduler") public class ClusterYarnSchedulerController { - + @Autowired private ClusterYarnSchedulerService clusterYarnSchedulerService; - + /** * 列表 */ @RequestMapping("/list") public Result list() { - + return Result.success(); } - + /** * 信息 */ @RequestMapping("/info") public Result info(Integer clusterId) { ClusterYarnScheduler clusterYarnScheduler = clusterYarnSchedulerService.getScheduler(clusterId); - + return Result.success(clusterYarnScheduler.getScheduler()); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody ClusterYarnScheduler clusterYarnScheduler) { clusterYarnSchedulerService.save(clusterYarnScheduler); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody ClusterYarnScheduler clusterYarnScheduler) { - + clusterYarnSchedulerService.updateById(clusterYarnScheduler); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { clusterYarnSchedulerService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/FrameInfoController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/FrameInfoController.java index 96d74a63..c6719a7a 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/FrameInfoController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/FrameInfoController.java @@ -32,10 +32,10 @@ @RestController @RequestMapping("api/frame") public class FrameInfoController { - + @Autowired private FrameInfoService frameInfoService; - + /** * 列表 */ @@ -43,45 +43,45 @@ public class FrameInfoController { public Result list() { return frameInfoService.getAllClusterFrame(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { FrameInfoEntity frameInfo = frameInfoService.getById(id); - + return Result.success().put("frameInfo", frameInfo); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody FrameInfoEntity frameInfo) { frameInfoService.save(frameInfo); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody FrameInfoEntity frameInfo) { frameInfoService.updateById(frameInfo); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { frameInfoService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceController.java index f8d66262..fc6ad81b 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceController.java @@ -17,8 +17,6 @@ package com.datasophon.api.controller; -import cn.hutool.core.io.FileUtil; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.datasophon.api.service.ClusterServiceInstanceService; import com.datasophon.api.service.FrameServiceRoleService; import com.datasophon.api.service.FrameServiceService; @@ -27,32 +25,36 @@ import com.datasophon.dao.entity.ClusterServiceInstanceEntity; import com.datasophon.dao.entity.FrameServiceEntity; import com.datasophon.dao.entity.FrameServiceRoleEntity; + +import java.io.File; +import java.util.List; + import lombok.extern.slf4j.Slf4j; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.File; -import java.util.List; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; + +import cn.hutool.core.io.FileUtil; @Slf4j @RestController @RequestMapping("api/frame/service") public class FrameServiceController { - + @Autowired private FrameServiceService frameVersionServiceService; - - + @Autowired private FrameServiceRoleService frameServiceRoleService; - - + @Autowired private ClusterServiceInstanceService clusterServiceInstanceService; - + /** * 列表 */ @@ -60,7 +62,7 @@ public class FrameServiceController { public Result list(Integer clusterId) { return frameVersionServiceService.getAllFrameService(clusterId); } - + /** * 根据servce id列表查询服务 */ @@ -68,37 +70,37 @@ public Result list(Integer clusterId) { public Result getServiceListByServiceIds(List serviceIds) { return frameVersionServiceService.getServiceListByServiceIds(serviceIds); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { FrameServiceEntity frameVersionService = frameVersionServiceService.getById(id); - + return Result.success().put("frameVersionService", frameVersionService); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody FrameServiceEntity frameVersionService) { frameVersionServiceService.save(frameVersionService); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody FrameServiceEntity frameVersionService) { frameVersionServiceService.updateById(frameVersionService); - + return Result.success(); } - + /** * 删除服务组件 */ @@ -115,15 +117,16 @@ public Result delete(@PathVariable("id") Integer id) { if (roleEntities != null && !roleEntities.isEmpty()) { return Result.error("Service 组件正在使用中。"); } - + // delete /DDP/packages 下的软件包 File targetPackageFile = new File(Constants.MASTER_MANAGE_PACKAGE_PATH, serviceEntity.getPackageName()); FileUtil.del(targetPackageFile); log.info("delete package file to: {}", targetPackageFile.getAbsolutePath()); - File targetPackageFileMd5 = new File(Constants.MASTER_MANAGE_PACKAGE_PATH, serviceEntity.getPackageName() + ".md5"); + File targetPackageFileMd5 = + new File(Constants.MASTER_MANAGE_PACKAGE_PATH, serviceEntity.getPackageName() + ".md5"); FileUtil.del(targetPackageFileMd5); log.info("delete package md5 file to: {}", targetPackageFileMd5.getAbsolutePath()); - + // 删除配置 frameServiceRoleService.remove(Wrappers.lambdaQuery() .eq(FrameServiceRoleEntity::getServiceId, id)); @@ -131,5 +134,5 @@ public Result delete(@PathVariable("id") Integer id) { frameVersionServiceService.removeById(id); return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceRoleController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceRoleController.java index aa341979..e5c915e2 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceRoleController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/FrameServiceRoleController.java @@ -34,13 +34,13 @@ @RestController @RequestMapping("api/frame/service/role") public class FrameServiceRoleController { - + @Autowired private FrameServiceRoleService frameServiceRoleService; - + @Autowired private AlertGroupService alertGroupService; - + /** * 查询服务对应的角色列表 */ @@ -48,56 +48,56 @@ public class FrameServiceRoleController { public Result getServiceRoleOfMaster(Integer clusterId, String serviceIds, Integer serviceRoleType) { return frameServiceRoleService.getServiceRoleList(clusterId, serviceIds, serviceRoleType); } - + @RequestMapping("/getNonMasterRoleList") public Result getNonMasterRoleList(Integer clusterId, String serviceIds) { return frameServiceRoleService.getNonMasterRoleList(clusterId, serviceIds); } - + @RequestMapping("/getServiceRoleByServiceName") public Result getServiceRoleByServiceName(Integer clusterId, Integer alertGroupId) { AlertGroupEntity alertGroupEntity = alertGroupService.getById(alertGroupId); return frameServiceRoleService.getServiceRoleByServiceName(clusterId, alertGroupEntity.getAlertGroupCategory()); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { FrameServiceRoleEntity frameServiceRole = frameServiceRoleService.getById(id); - + return Result.success().put("frameServiceRole", frameServiceRole); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody FrameServiceRoleEntity frameServiceRole) { frameServiceRoleService.save(frameServiceRole); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody FrameServiceRoleEntity frameServiceRole) { frameServiceRoleService.updateById(frameServiceRole); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { frameServiceRoleService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/HostInstallController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/HostInstallController.java index ba2aeef5..d1315736 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/HostInstallController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/HostInstallController.java @@ -21,20 +21,28 @@ import com.datasophon.api.service.InstallService; import com.datasophon.common.utils.Result; -import javax.validation.constraints.*; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @Validated @RestController @RequestMapping("host/install") public class HostInstallController { - + @Autowired private InstallService installService; - + /** * 获取安装步骤 */ @@ -42,7 +50,7 @@ public class HostInstallController { public Result getInstallStep(Integer type) { return installService.getInstallStep(type); } - + /** * 解析主机列表 */ @@ -56,7 +64,7 @@ public Result analysisHostList(@RequestParam Integer clusterId, @RequestParam Integer pageSize) { return installService.analysisHostList(clusterId, hosts, sshUser, sshPort, page, pageSize); } - + /** * 查询主机校验状态 */ @@ -65,7 +73,7 @@ public Result analysisHostList(@RequestParam Integer clusterId, public Result getHostCheckStatus(Integer clusterId, String sshUser, Integer sshPort) { return installService.getHostCheckStatus(clusterId, sshUser, sshPort); } - + /** * 重新进行主机环境校验 */ @@ -74,7 +82,7 @@ public Result getHostCheckStatus(Integer clusterId, String sshUser, Integer sshP public Result rehostCheck(Integer clusterId, String hostnames, String sshUser, Integer sshPort) { return installService.rehostCheck(clusterId, hostnames, sshUser, sshPort); } - + /** * 查询主机校验是否全部完成 */ @@ -83,7 +91,7 @@ public Result rehostCheck(Integer clusterId, String hostnames, String sshUser, I public Result hostCheckCompleted(Integer clusterId) { return installService.hostCheckCompleted(clusterId); } - + /** * 主机管理agent分发安装进度列表 */ @@ -92,12 +100,12 @@ public Result hostCheckCompleted(Integer clusterId) { public Result dispatcherHostAgentList(Integer clusterId, Integer installStateCode, Integer page, Integer pageSize) { return installService.dispatcherHostAgentList(clusterId, installStateCode, page, pageSize); } - + @PostMapping("/dispatcherHostAgentCompleted") public Result dispatcherHostAgentCompleted(Integer clusterId) { return installService.dispatcherHostAgentCompleted(clusterId); } - + /** * 主机管理agent分发取消 */ @@ -105,7 +113,7 @@ public Result dispatcherHostAgentCompleted(Integer clusterId) { public Result cancelDispatcherHostAgent(Integer clusterId, String hostname, Integer installStateCode) { return installService.cancelDispatcherHostAgent(clusterId, hostname, installStateCode); } - + /** * 主机管理agent分发安装重试 * @@ -117,7 +125,7 @@ public Result cancelDispatcherHostAgent(Integer clusterId, String hostname, Inte public Result reStartDispatcherHostAgent(Integer clusterId, String hostnames) { return installService.reStartDispatcherHostAgent(clusterId, hostnames); } - + /** * 主机管理agent操作(启动(start)、停止(stop)、重启(restart)) * @param clusterHostIds @@ -130,7 +138,7 @@ public Result generateHostAgentCommand( @RequestParam String commandType) throws Exception { return installService.generateHostAgentCommand(clusterHostIds, commandType); } - + /** * 启动/停止 主机上服务启动 * @param clusterHostIds @@ -139,9 +147,9 @@ public Result generateHostAgentCommand( */ @PostMapping("/generateHostServiceCommand") public Result generateHostServiceCommand( - @RequestParam String clusterHostIds, - @RequestParam String commandType) throws Exception { + @RequestParam String clusterHostIds, + @RequestParam String commandType) throws Exception { return installService.generateHostServiceCommand(clusterHostIds, commandType); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/LoginController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/LoginController.java index f9ab7efe..4accf8d2 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/LoginController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/LoginController.java @@ -28,7 +28,7 @@ import com.datasophon.dao.entity.UserInfoEntity; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.Map; @@ -39,20 +39,24 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("") public class LoginController { - + private static final Logger logger = LoggerFactory.getLogger(LoginController.class); - + @Autowired private SessionService sessionService; - + @Autowired private Authenticator authenticator; - + /** * login * @@ -62,32 +66,32 @@ public class LoginController { * @param response response * @return login result */ - + @RequestMapping("/login") public Result login(@RequestParam(value = "username") String userName, @RequestParam(value = "password") String userPassword, HttpServletRequest request, HttpServletResponse response) { logger.info("login user name: {} ", userName); - + // user name check if (StringUtils.isEmpty(userName)) { return Result.error(Status.USER_NAME_NULL.getCode(), Status.USER_NAME_NULL.getMsg()); } - + // user ip check String ip = HttpUtils.getClientIpAddress(request); if (StringUtils.isEmpty(ip)) { return Result.error(IP_IS_EMPTY.getCode(), IP_IS_EMPTY.getMsg()); } - + // verify username and password Result result = authenticator.authenticate(userName, userPassword, ip); if (result.getCode() != Status.SUCCESS.getCode()) { return result; } - + response.setStatus(HttpStatus.SC_OK); Map cookieMap = (Map) result.getData(); for (Map.Entry cookieEntry : cookieMap.entrySet()) { @@ -95,10 +99,10 @@ public Result login(@RequestParam(value = "username") String userName, cookie.setHttpOnly(true); response.addCookie(cookie); } - + return result; } - + /** * sign out * diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/NoticeGroupUserController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/NoticeGroupUserController.java index 457bf46e..b4ac6fde 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/NoticeGroupUserController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/NoticeGroupUserController.java @@ -34,57 +34,57 @@ @RestController @RequestMapping("api/notice/group/user") public class NoticeGroupUserController { - + @Autowired private NoticeGroupUserService noticeGroupUserService; - + /** * 列表 */ @RequestMapping("/list") public Result list(@RequestParam Map params) { - + return Result.success(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { NoticeGroupUserEntity noticeGroupUser = noticeGroupUserService.getById(id); - + return Result.success().put("noticeGroupUser", noticeGroupUser); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody NoticeGroupUserEntity noticeGroupUser) { noticeGroupUserService.save(noticeGroupUser); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody NoticeGroupUserEntity noticeGroupUser) { noticeGroupUserService.updateById(noticeGroupUser); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { noticeGroupUserService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ParcelController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ParcelController.java index 707031f7..85e2728b 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ParcelController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ParcelController.java @@ -14,15 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.api.controller; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.StreamProgress; -import cn.hutool.core.util.NumberUtil; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.datasophon.api.load.LoadServiceMeta; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.FrameInfoService; @@ -35,16 +29,9 @@ import com.datasophon.dao.entity.FrameServiceEntity; import com.datasophon.dao.model.ComponentVO; import com.datasophon.dao.model.ParcelInfoVO; -import com.google.common.util.concurrent.AtomicDouble; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.SystemUtils; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; import java.io.File; import java.io.IOException; @@ -58,6 +45,25 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.util.concurrent.AtomicDouble; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.StreamProgress; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.http.HttpUtil; + /** * * 远程框架管理(Parcel)管理,支持 DDP 从第三方加载框架并安装 @@ -69,32 +75,29 @@ @RestController @RequestMapping("/cluster/parcel") public class ParcelController implements DisposableBean { - - + /** * 组件下载进程缓存,不会安装太多组件的,直接采用内存 */ - final Map COMPONENT_CACHE = new ConcurrentHashMap<>(); - - + final Map componentCache = new ConcurrentHashMap<>(); + /** * 异步操作的任务 */ - final Map ASYNC_TASK_CACHE = new ConcurrentHashMap<>(); - - + final Map asyncTaskCache = new ConcurrentHashMap<>(); + @Autowired private FrameServiceService frameServiceService; - + @Autowired private FrameInfoService frameInfoService; - + @Autowired private ClusterInfoService clusterInfoService; - + @Autowired LoadServiceMeta loadServiceMeta; - + /** * 列表 */ @@ -102,7 +105,7 @@ public class ParcelController implements DisposableBean { public Result list() { return Result.success(""); } - + /** * 解析 URL 中的 parcel 信息 */ @@ -111,8 +114,8 @@ public Result parseParcel(ParcelInfoVO info) { log.info(JSON.toJSONString(info)); String url = info.getUrl(); // 解析 URL - if(!url.endsWith("manifest.json")) { - if(url.endsWith("/")) { + if (!url.endsWith("manifest.json")) { + if (url.endsWith("/")) { url = url + "manifest.json"; } else { url = url + "/manifest.json"; @@ -120,22 +123,24 @@ public Result parseParcel(ParcelInfoVO info) { } // 查询所有的 框架 List installFrames = frameInfoService.list(); - final Map> frameCodeMapping = installFrames.stream().collect(Collectors.groupingBy(FrameInfoEntity::getFrameCode)); - + final Map> frameCodeMapping = + installFrames.stream().collect(Collectors.groupingBy(FrameInfoEntity::getFrameCode)); + try { JSONObject json = JSON.parseObject(httpGet(url)); - ParcelInfoVO parcelInfo = JSON.toJavaObject((JSONObject)json.get("parcel"), ParcelInfoVO.class); - if(frameCodeMapping.get(parcelInfo.getMeta()) == null) { + ParcelInfoVO parcelInfo = JSON.toJavaObject((JSONObject) json.get("parcel"), ParcelInfoVO.class); + if (frameCodeMapping.get(parcelInfo.getMeta()) == null) { // 不支持的框架版本 return Result.error("Unsupported frame: " + parcelInfo.getMeta()); } parcelInfo.setUrl(url); parcelInfo.setLastUpdated(json.getLong("lastUpdated")); - if(parcelInfo.getComponents() != null && !parcelInfo.getComponents().isEmpty()) { + if (parcelInfo.getComponents() != null && !parcelInfo.getComponents().isEmpty()) { // 仅过滤支持的架构 - final List componentVOS = parcelInfo.getComponents(); /*.stream().filter(it -> { - return SystemUtils.OS_ARCH.equalsIgnoreCase(it.getArch()); - }).collect(Collectors.toList()); */ + final List componentVOS = parcelInfo.getComponents(); /* + * .stream().filter(it -> { return SystemUtils.OS_ARCH. equalsIgnoreCase(it.getArch()); + * }).collect(Collectors.toList()); + */ parcelInfo.setComponents(componentVOS); log.info(JSON.toJSONString(parcelInfo)); return Result.success(parcelInfo); @@ -146,8 +151,7 @@ public Result parseParcel(ParcelInfoVO info) { } return Result.error("Invalid DHH Parcel Endpoint!"); } - - + /** * 下载 Parcel */ @@ -156,8 +160,8 @@ public Result downloadParcel(ParcelInfoVO info) { log.info(JSON.toJSONString(info)); String url = info.getUrl(); // 解析 URL - if(!url.endsWith("manifest.json")) { - if(url.endsWith("/")) { + if (!url.endsWith("manifest.json")) { + if (url.endsWith("/")) { url = url + "manifest.json"; } else { url = url + "/manifest.json"; @@ -165,31 +169,32 @@ public Result downloadParcel(ParcelInfoVO info) { } try { List installFrames = frameInfoService.list(); - final Map> frameCodeMapping = installFrames.stream().collect(Collectors.groupingBy(FrameInfoEntity::getFrameCode)); - + final Map> frameCodeMapping = + installFrames.stream().collect(Collectors.groupingBy(FrameInfoEntity::getFrameCode)); + JSONObject json = JSONObject.parseObject(httpGet(url)); final ParcelInfoVO parcelInfo = JSON.toJavaObject((JSONObject) json.get("parcel"), ParcelInfoVO.class); parcelInfo.setUrl(url); parcelInfo.setLastUpdated(json.getLong("lastUpdated")); - if(frameCodeMapping.get(parcelInfo.getMeta()) == null) { + if (frameCodeMapping.get(parcelInfo.getMeta()) == null) { // 不支持的框架版本 return Result.error("Unsupported frame: " + parcelInfo.getMeta()); } - - if(parcelInfo.getComponents() != null && !parcelInfo.getComponents().isEmpty()) { + + if (parcelInfo.getComponents() != null && !parcelInfo.getComponents().isEmpty()) { final List componentVOS = parcelInfo.getComponents().stream().filter(it -> { return info.getParcelName().equals(it.getName()); }).collect(Collectors.toList()); - if(componentVOS.isEmpty()) { + if (componentVOS.isEmpty()) { throw new IllegalStateException("No component package: " + info.getParcelName()); } final ComponentVO componentVO = componentVOS.get(0); final String packagePath = getParcelPath(url, componentVO.getPackageName()); File ddhTmpDir = new File(SystemUtils.getJavaIoTmpDir(), "jdh"); - if(!ddhTmpDir.exists()) { + if (!ddhTmpDir.exists()) { ddhTmpDir.mkdirs(); } - + // 开始下载,这里需要做成带进度 componentVO.setProcess(0.0f); componentVO.setStep("download"); @@ -201,12 +206,12 @@ public Result downloadParcel(ParcelInfoVO info) { // 开始下载,这里需要做成带进度 final AtomicDouble process = new AtomicDouble(0.0f); File filePath = HttpUtil.downloadFileFromUrl(packagePath, ddhTmpDir, new StreamProgress() { - + @Override public void start() { log.info("start to download: {} to dir: {}", packagePath, ddhTmpDir.getAbsolutePath()); } - + @Override public void progress(long total, long progressSize) { float p = progressSize * 1.0f / total; @@ -218,7 +223,7 @@ public void progress(long total, long progressSize) { process.set(per + 0.1f); } } - + @Override public void finish() { } @@ -231,20 +236,22 @@ public void finish() { componentVO.setProcess(1.0f); componentVO.setStep("download"); componentVO.setState("success"); - log.info("download {} success, finish process: {}", componentVO.getPackageName(), componentVO.getProcess()); + log.info("download {} success, finish process: {}", componentVO.getPackageName(), + componentVO.getProcess()); } catch (Exception e) { log.error("download parcel error!", e); // 下载失败 componentVO.setProcess(1.0f); componentVO.setStep("download"); componentVO.setState("fail"); - log.info("download {} fail, finish process: {}", componentVO.getPackageName(), componentVO.getProcess()); + log.info("download {} fail, finish process: {}", componentVO.getPackageName(), + componentVO.getProcess()); } }); - ASYNC_TASK_CACHE.put(componentVO.getMd5(), future); + asyncTaskCache.put(componentVO.getMd5(), future); // 框架支持的版本 componentVO.setMeta(parcelInfo.getMeta()); - COMPONENT_CACHE.put(componentVO.getMd5(), componentVO); + componentCache.put(componentVO.getMd5(), componentVO); log.info(JSON.toJSONString(componentVO)); return Result.success(componentVO); } @@ -254,7 +261,7 @@ public void finish() { return Result.error("download parcel error, Cause: " + e.getMessage()); } } - + /** * Install Parcel */ @@ -262,53 +269,52 @@ public void finish() { public Result installParcel(ComponentVO info) { // 安装:验证 md5 or hash、安装,推送到 worker 节点,并且读取 meta 信息,写入数据库 log.info(JSON.toJSONString(info)); - ComponentVO vo = COMPONENT_CACHE.get(info.getMd5()); - if(vo == null) { + ComponentVO vo = componentCache.get(info.getMd5()); + if (vo == null) { return Result.error("component: " + info.getPackageName() + " not found!"); } - + // 应用包 File packageFile = new File(vo.getHash()); - if(!packageFile.exists()) { + if (!packageFile.exists()) { return Result.error("component: " + info.getPackageName() + " not found!"); } - + // 检验是否合法 List installFrames = frameInfoService.list(); - final Map> frameCodeMapping = installFrames.stream().collect(Collectors.groupingBy(FrameInfoEntity::getFrameCode)); + final Map> frameCodeMapping = + installFrames.stream().collect(Collectors.groupingBy(FrameInfoEntity::getFrameCode)); final List frameInfoEntityList = frameCodeMapping.get(vo.getMeta()); - if(frameInfoEntityList == null || frameInfoEntityList.isEmpty()) { + if (frameInfoEntityList == null || frameInfoEntityList.isEmpty()) { // 不支持的框架版本 return Result.error("Unsupported frame: " + vo.getMeta()); } // 当前安装的框架 final FrameInfoEntity frameInfo = frameInfoEntityList.get(0); - + // 是否已经安装了组件? List installService = frameServiceService.list( Wrappers.lambdaQuery() .eq(FrameServiceEntity::getServiceName, vo.getName()) - .eq(FrameServiceEntity::getServiceVersion, vo.getVersion()) - ); - if(installService.isEmpty()) { + .eq(FrameServiceEntity::getServiceVersion, vo.getVersion())); + if (installService.isEmpty()) { // 防止包名称相同,覆盖了已经安装的,也防止包名称的污染 installService = frameServiceService.list( Wrappers.lambdaQuery() - .eq(FrameServiceEntity::getPackageName, vo.getPackageName()) - ); + .eq(FrameServiceEntity::getPackageName, vo.getPackageName())); } // 已经安装的服务 - if(installService != null && !installService.isEmpty()) { + if (installService != null && !installService.isEmpty()) { return Result.error("已经安装组件: " + vo.getName() + "-" + vo.getVersion()); } - + vo.setProcess(0.0f); vo.setStep("install"); vo.setState("executing"); final CompletableFuture future = CompletableFuture.runAsync(() -> { try { String packageMd5 = FileUtils.md5(packageFile); - if(!StringUtils.equals(packageMd5, vo.getMd5())) { + if (!StringUtils.equals(packageMd5, vo.getMd5())) { throw new IllegalStateException("component: " + info.getPackageName() + " md5 invalid!"); } // 生成 md 5 校验文件 @@ -318,9 +324,9 @@ public Result installParcel(ComponentVO info) { vo.setProcess(0.3f); vo.setStep("install"); vo.setState("executing"); - + Thread.sleep(5000); - + // mv 到 /DDP/packages File targetPackageFile = new File(Constants.MASTER_MANAGE_PACKAGE_PATH, packageFile.getName()); FileUtil.move(packageFile, targetPackageFile, true); @@ -328,19 +334,20 @@ public Result installParcel(ComponentVO info) { File targetPackageFileMd5 = new File(Constants.MASTER_MANAGE_PACKAGE_PATH, packageFileMd5.getName()); FileUtil.move(packageFileMd5, targetPackageFileMd5, true); log.info("move package md5 file to: {}", targetPackageFileMd5.getAbsolutePath()); - + // 合法,开始安装 vo.setProcess(0.6f); vo.setStep("install"); vo.setState("executing"); - + Thread.sleep(5000); - + String frameCode = frameInfo.getFrameCode(); List clusters = clusterInfoService.list(); // service ddl 存在的目录,读取压缩包内的 meta 文件 String tempFileName = "/meta/service_ddl.json"; - String serviceDdl = FileUtils.readTargzTextFile(targetPackageFile, tempFileName, StandardCharsets.UTF_8); + String serviceDdl = + FileUtils.readTargzTextFile(targetPackageFile, tempFileName, StandardCharsets.UTF_8); String serviceName = vo.getName(); loadServiceMeta.parseServiceDdl(frameCode, clusters, frameInfo, serviceName, serviceDdl); // 成功,安装结束 @@ -355,19 +362,18 @@ public Result installParcel(ComponentVO info) { vo.setState("fail"); } }); - ASYNC_TASK_CACHE.put(vo.getMd5(), future); + asyncTaskCache.put(vo.getMd5(), future); // 返回安装,异步获取进度 return Result.success(vo); } - - + /** * 获取 Process 进度,简易方案 */ @GetMapping("/process") public Result getProcess(ComponentVO info) { - ComponentVO vo = COMPONENT_CACHE.get(info.getMd5()); - if(vo == null) { + ComponentVO vo = componentCache.get(info.getMd5()); + if (vo == null) { vo = new ComponentVO(); // 错误的 ID vo.setProcess(0.0f); @@ -377,9 +383,7 @@ public Result getProcess(ComponentVO info) { } return Result.success(vo); } - - - + /** * http get * @param url @@ -387,12 +391,12 @@ public Result getProcess(ComponentVO info) { * @throws IOException */ private String httpGet(String url) throws IOException { - if(StringUtils.isBlank(url)) { + if (StringUtils.isBlank(url)) { throw new IllegalStateException("Invalid DDP Parcel Endpoint!"); } return HttpUtil.get(url, 20000); } - + /** * parcel name * @param url @@ -402,28 +406,29 @@ private String httpGet(String url) throws IOException { private String getParcelPath(String url, String resourceName) { final URI uri = URI.create(url); final Path urlParentPath = Paths.get(uri.getPath()).getParent(); - + String urlStr = uri.toString(); String prefix = urlStr.substring(0, urlStr.lastIndexOf(urlParentPath.toString())); - - URI newUrl = "/".equals(urlParentPath.toString()) ? - URI.create(prefix + urlParentPath.toString() + resourceName) : URI.create(prefix + urlParentPath.toString() + "/" + resourceName); + + URI newUrl = "/".equals(urlParentPath.toString()) ? URI.create(prefix + urlParentPath.toString() + resourceName) + : URI.create(prefix + urlParentPath.toString() + "/" + resourceName); return newUrl.toString(); } - + /** * 当 api-server 停止时,结束没有完成的任务 * @throws Exception */ @Override public void destroy() throws Exception { - for (Map.Entry entry : ASYNC_TASK_CACHE.entrySet()) { + for (Map.Entry entry : asyncTaskCache.entrySet()) { final CompletableFuture future = entry.getValue(); try { if (!future.isDone()) { future.cancel(true); } - } catch (Exception ignore) {} + } catch (Exception ignore) { + } } } } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/RoleInfoController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/RoleInfoController.java index 3473e953..3641c0e3 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/RoleInfoController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/RoleInfoController.java @@ -34,57 +34,57 @@ @RestController @RequestMapping("/api/role/info") public class RoleInfoController { - + @Autowired private RoleInfoService roleInfoService; - + /** * 列表 */ @RequestMapping("/list") public Result list(@RequestParam Map params) { - + return Result.success(); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { RoleInfoEntity roleInfo = roleInfoService.getById(id); - + return Result.success().put("roleInfo", roleInfo); } - + /** * 保存 */ @RequestMapping("/save") public Result save(@RequestBody RoleInfoEntity roleInfo) { roleInfoService.save(roleInfo); - + return Result.success(); } - + /** * 修改 */ @RequestMapping("/update") public Result update(@RequestBody RoleInfoEntity roleInfo) { roleInfoService.updateById(roleInfo); - + return Result.success(); } - + /** * 删除 */ @RequestMapping("/delete") public Result delete(@RequestBody Integer[] ids) { roleInfoService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/ServiceInstallController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/ServiceInstallController.java index 10e9b215..7a9e05d1 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/ServiceInstallController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/ServiceInstallController.java @@ -17,27 +17,34 @@ package com.datasophon.api.controller; -import com.alibaba.fastjson.JSONArray; import com.datasophon.api.security.UserPermission; import com.datasophon.api.service.ServiceInstallService; import com.datasophon.common.model.HostServiceRoleMapping; import com.datasophon.common.model.ServiceConfig; import com.datasophon.common.model.ServiceRoleHostMapping; import com.datasophon.common.utils.Result; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.alibaba.fastjson.JSONArray; + @RestController @RequestMapping("service/install") public class ServiceInstallController { - + @Autowired ServiceInstallService serviceInstallService; - + /** * 根据服务名称查询服务配置选项 */ @@ -45,7 +52,7 @@ public class ServiceInstallController { public Result getServiceConfigOption(Integer clusterId, String serviceName) { return serviceInstallService.getServiceConfigOption(clusterId, serviceName); } - + /** * 保存服务配置 */ @@ -55,9 +62,9 @@ public Result saveServiceConfig(Integer clusterId, String serviceName, String se JSONArray jsonArray = JSONArray.parseArray(serviceConfig); List list = jsonArray.toJavaList(ServiceConfig.class); return serviceInstallService.saveServiceConfig(clusterId, serviceName, list, roleGroupId); - + } - + /** * 保存服务角色与主机对应关系 */ @@ -66,7 +73,7 @@ public Result saveServiceRoleHostMapping(@RequestBody List list) { - + return serviceInstallService.saveHostServiceRoleMapping(clusterId, list); } - + /** * 服务部署总览 */ @@ -93,27 +100,27 @@ public Result saveHostServiceRoleMapping(@PathVariable("clusterId") Integer clus public Result getServiceRoleDeployOverview(Integer clusterId) { return serviceInstallService.getServiceRoleDeployOverview(clusterId); } - + /** * 开始安装服务 */ @RequestMapping("/startInstallService/{clusterId}") public Result startInstallService(@PathVariable("clusterId") Integer clusterId, @RequestBody List commandIds) { - + return serviceInstallService.startInstallService(clusterId, commandIds); } - + /** * 下载安装包 */ @GetMapping("/downloadPackage") public void downloadPackage(String packageName, String cpuArchitecture, HttpServletResponse response) throws IOException { - + serviceInstallService.downloadPackage(packageName, response); } - + /** * 下载额外资源 */ @@ -121,10 +128,10 @@ public void downloadPackage(String packageName, String cpuArchitecture, public void downloadResource(String frameCode, String serviceRoleName, String resource, HttpServletResponse response) throws IOException { - + serviceInstallService.downloadResource(frameCode, serviceRoleName, resource, response); } - + /** * 服务部署总览 */ @@ -132,5 +139,5 @@ public void downloadResource(String frameCode, String serviceRoleName, public Result checkServiceDependency(Integer clusterId, String serviceIds) { return serviceInstallService.checkServiceDependency(clusterId, serviceIds); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/controller/UserInfoController.java b/datasophon-api/src/main/java/com/datasophon/api/controller/UserInfoController.java index 7851553e..d714c773 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/controller/UserInfoController.java +++ b/datasophon-api/src/main/java/com/datasophon/api/controller/UserInfoController.java @@ -17,7 +17,6 @@ package com.datasophon.api.controller; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.datasophon.api.enums.Status; import com.datasophon.api.security.UserPermission; import com.datasophon.api.service.UserInfoService; @@ -26,23 +25,26 @@ import com.datasophon.common.utils.EncryptionUtils; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.UserInfoEntity; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @RestController @RequestMapping("api/user") public class UserInfoController { - + @Autowired private UserInfoService userInfoService; - + /** * 列表带分页 */ @@ -50,7 +52,7 @@ public class UserInfoController { public Result list(String username, Integer page, Integer pageSize) { return userInfoService.getUserListByPage(username, page, pageSize); } - + /** * 查询所有用户 */ @@ -59,27 +61,27 @@ public Result all() { List list = userInfoService.lambdaQuery().ne(UserInfoEntity::getId, 1).list(); return Result.success(list); } - + /** * 信息 */ @RequestMapping("/info/{id}") public Result info(@PathVariable("id") Integer id) { UserInfoEntity userInfo = userInfoService.getById(id); - + return Result.success().put(Constants.DATA, userInfo); } - + /** * 保存 */ @RequestMapping("/save") @UserPermission public Result save(@RequestBody UserInfoEntity userInfo) { - + return userInfoService.createUser(userInfo); } - + /** * 修改 */ @@ -98,10 +100,10 @@ public Result update(@RequestBody UserInfoEntity userInfo) { String password = userInfo.getPassword(); userInfo.setPassword(EncryptionUtils.getMd5(password)); userInfoService.updateById(userInfo); - + return Result.success(); } - + /** * 删除 */ @@ -116,8 +118,8 @@ public Result delete(@RequestBody Integer[] ids) { return Result.error(Status.USER_NO_OPERATION_PERM.getMsg()); } userInfoService.removeByIds(Arrays.asList(ids)); - + return Result.success(); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiException.java b/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiException.java index 1055f5e2..71088b1b 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiException.java +++ b/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiException.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.api.exceptions; import static java.lang.annotation.ElementType.METHOD; @@ -30,6 +31,6 @@ @Retention(RUNTIME) @Target(METHOD) public @interface ApiException { - + Status value(); } diff --git a/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiExceptionHandler.java b/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiExceptionHandler.java index 81fc8584..f13914fd 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiExceptionHandler.java +++ b/datasophon-api/src/main/java/com/datasophon/api/exceptions/ApiExceptionHandler.java @@ -14,10 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.api.exceptions; import com.datasophon.api.enums.Status; import com.datasophon.common.utils.Result; + +import java.util.Set; +import java.util.stream.Collectors; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -26,20 +34,15 @@ import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; -import javax.validation.ConstraintViolation; -import javax.validation.ConstraintViolationException; -import java.util.Set; -import java.util.stream.Collectors; - /** * Exception Handler */ @ControllerAdvice @ResponseBody public class ApiExceptionHandler { - + private static final Logger logger = LoggerFactory.getLogger(ApiExceptionHandler.class); - + @ExceptionHandler(Exception.class) public Result exceptionHandler(Exception e, HandlerMethod hm) { ApiException ce = hm.getMethodAnnotation(ApiException.class); @@ -51,7 +54,7 @@ public Result exceptionHandler(Exception e, HandlerMethod hm) { logger.error(st.getMsg(), e); return Result.error(st.getCode(), st.getMsg()); } - + @ExceptionHandler(ConstraintViolationException.class) public Result constraintViolationException(ConstraintViolationException e) { Set set = e.getConstraintViolations() @@ -60,12 +63,12 @@ public Result constraintViolationException(ConstraintViolationException e) { .collect(Collectors.toSet()); return Result.error(String.join(",", set)); } - + @ExceptionHandler(MethodArgumentTypeMismatchException.class) public Result exceptionHandler(MethodArgumentTypeMismatchException e) { return Result.error("参数类型错不匹配:" + e.getMessage()); } - + /** * business exception */ diff --git a/datasophon-api/src/main/java/com/datasophon/api/interceptor/LocaleChangeInterceptor.java b/datasophon-api/src/main/java/com/datasophon/api/interceptor/LocaleChangeInterceptor.java index 34220aae..b5039c2d 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/interceptor/LocaleChangeInterceptor.java +++ b/datasophon-api/src/main/java/com/datasophon/api/interceptor/LocaleChangeInterceptor.java @@ -32,7 +32,7 @@ import org.springframework.web.util.WebUtils; public class LocaleChangeInterceptor extends HandlerInterceptorAdapter { - + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { Cookie cookie = WebUtils.getCookie(request, Constants.LOCALE_LANGUAGE); @@ -47,10 +47,10 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons } return true; } - + @Nullable protected Locale parseLocaleValue(String localeValue) { return StringUtils.parseLocale(localeValue); } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/interceptor/LoginHandlerInterceptor.java b/datasophon-api/src/main/java/com/datasophon/api/interceptor/LoginHandlerInterceptor.java index cc94226c..e5a80456 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/interceptor/LoginHandlerInterceptor.java +++ b/datasophon-api/src/main/java/com/datasophon/api/interceptor/LoginHandlerInterceptor.java @@ -23,7 +23,7 @@ import com.datasophon.dao.mapper.UserInfoMapper; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,15 +37,15 @@ * login interceptor, must login first */ public class LoginHandlerInterceptor implements HandlerInterceptor { - + private static final Logger logger = LoggerFactory.getLogger(LoginHandlerInterceptor.class); - + @Autowired private UserInfoMapper userMapper; - + @Autowired private Authenticator authenticator; - + /** * Intercept the execution of a handler. Called after HandlerMapping determined * @param request current HTTP request @@ -78,5 +78,5 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons request.setAttribute(Constants.SESSION_USER, user); return true; } - + } diff --git a/datasophon-api/src/main/java/com/datasophon/api/interceptor/UserPermissionHandler.java b/datasophon-api/src/main/java/com/datasophon/api/interceptor/UserPermissionHandler.java index 9e973ce1..0d12c70e 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/interceptor/UserPermissionHandler.java +++ b/datasophon-api/src/main/java/com/datasophon/api/interceptor/UserPermissionHandler.java @@ -17,31 +17,33 @@ package com.datasophon.api.interceptor; -import com.datasophon.api.exceptions.ServiceException; import com.datasophon.api.enums.Status; +import com.datasophon.api.exceptions.ServiceException; import com.datasophon.api.security.UserPermission; import com.datasophon.api.service.ClusterRoleUserService; import com.datasophon.api.utils.SecurityUtils; import com.datasophon.common.Constants; import com.datasophon.dao.entity.UserInfoEntity; + +import java.util.Map; +import java.util.Objects; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Map; -import java.util.Objects; - public class UserPermissionHandler implements HandlerInterceptor { - + private static final Logger logger = LoggerFactory.getLogger(UserPermissionHandler.class); - + @Autowired private ClusterRoleUserService clusterUserService; - + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { if (handler instanceof HandlerMethod) { @@ -69,7 +71,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons } } } - + return true; } } diff --git a/datasophon-api/src/main/java/com/datasophon/api/migration/DatabaseMigration.java b/datasophon-api/src/main/java/com/datasophon/api/migration/DatabaseMigration.java index 02c0857f..2eec149b 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/migration/DatabaseMigration.java +++ b/datasophon-api/src/main/java/com/datasophon/api/migration/DatabaseMigration.java @@ -19,13 +19,31 @@ package com.datasophon.api.migration; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.utils.FileUtils; -import lombok.extern.slf4j.Slf4j; + import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.ibatis.jdbc.SQL; import org.apache.ibatis.jdbc.ScriptRunner; + +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import lombok.extern.slf4j.Slf4j; + import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; @@ -36,250 +54,252 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ResourceUtils; -import java.io.*; -import java.sql.Connection; -import java.sql.DriverManager; -import java.util.*; -import java.util.stream.Collectors; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; @Slf4j @Component public class DatabaseMigration { - - public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; - - private static final String MIGRATION_HOME = "conf/db/migration"; - - private static final String MIGRATION_TABLE_NAME = "migration_history"; - - public final static String SPLIT = "__"; - - private static final String TABLE_CREATE_SQL = "CREATE TABLE `migration_history` (" + - " `version` varchar(128) NOT NULL," + - " `execute_user` varchar(128) NOT NULL," + - " `execute_date` timestamp NOT NULL," + - " `success` tinyint(1) NOT NULL," + - " PRIMARY KEY (`version`)" + - ");"; - - @Value("${spring.datasource.url}") - private String url; - - @Value("${spring.datasource.username}") - private String username; - - @Value("${spring.datasource.password}") - private String password; - - private final JdbcTemplate jdbcTemplate; - - public DatabaseMigration(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } - - public void migration() { - prepareMigrationTable(); - Set migrations = getMigrations(); - if (CollectionUtils.isEmpty(migrations)) { - printCurrentVersion(); - TreeSet allMigrations = getAllMigrations(); - if (CollUtil.isEmpty(allMigrations)) { - log.info("No migration required "); - } else { - log.info("No migration required , current database version is " + allMigrations.last().getVersion()); - } - - return; - } - RuntimeException exception = doMigrations((TreeSet) migrations); - printCurrentVersion(); - if (exception != null) { - throw exception; - } - } - - private Set getMigrations() { - TreeSet migrations = getAllMigrations(); - if (migrations.isEmpty()) { - log.warn("No migration file was found!"); - return Collections.emptySet(); - } - // query migration histories - TreeSet migrationHistories = new TreeSet<>(jdbcTemplate.query("select * from migration_history", new BeanPropertyRowMapper<>(Migration.class))); - // filter the migrations that need to do - Set migrationsToDo; - if (CollectionUtils.isEmpty(migrationHistories)) { - return migrations; - } else { - Migration lastMigration = migrationHistories.last(); - migrationsToDo = migrations.tailSet(lastMigration, !lastMigration.isSuccess()); + + public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + private static final String MIGRATION_HOME = "conf/db/migration"; + + private static final String MIGRATION_TABLE_NAME = "migration_history"; + + public static final String SPLIT = "__"; + + private static final String TABLE_CREATE_SQL = "CREATE TABLE `migration_history` (" + + " `version` varchar(128) NOT NULL," + + " `execute_user` varchar(128) NOT NULL," + + " `execute_date` timestamp NOT NULL," + + " `success` tinyint(1) NOT NULL," + + " PRIMARY KEY (`version`)" + + ");"; + + @Value("${spring.datasource.url}") + private String url; + + @Value("${spring.datasource.username}") + private String username; + + @Value("${spring.datasource.password}") + private String password; + + private final JdbcTemplate jdbcTemplate; + + public DatabaseMigration(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; } - return migrationsToDo; - } - - private RuntimeException doMigrations(TreeSet migrations) { - for (Migration migration : migrations) { - log.info("start migration, version: " + migration.getVersion()); - migration.setExecuteUser(username); - migration.setExecuteDate(new Date()); - migration.setSuccess(doMigration(migration)); - upsertMigration(migration); - if (!migration.isSuccess()) { - return new RuntimeException("Migration break at version " + migration.getVersion()); - } else { - log.info("Migration success! version: " + migration.getVersion()); - } - } - log.info("The migration is complete , The latest database version is " + migrations.last().getVersion()); - return null; - } - - private boolean doMigration(Migration migration) { - - Resource ddlFile = migration.getUpgradeDDLFile(), dmlFile = migration.getUpgradeDMLFile(); - if (runScript(ddlFile, true) && runScript(dmlFile, true)) { - return true; + + public void migration() { + prepareMigrationTable(); + Set migrations = getMigrations(); + if (CollectionUtils.isEmpty(migrations)) { + printCurrentVersion(); + TreeSet allMigrations = getAllMigrations(); + if (CollUtil.isEmpty(allMigrations)) { + log.info("No migration required "); + } else { + log.info("No migration required , current database version is " + allMigrations.last().getVersion()); + } + + return; + } + RuntimeException exception = doMigrations((TreeSet) migrations); + printCurrentVersion(); + if (exception != null) { + throw exception; + } } - log.error("Migration failure! version: " + migration.getVersion() + ". A rollback is about to be performed"); - Resource rollbackFile = migration.getRollbackFile(); - if (rollbackFile != null) { - runScript(rollbackFile, false); - log.info("The rollback script (" + rollbackFile.getFilename() + ") is successfully executed"); - } else { - log.warn("The rollback script does not exist. Skip execution"); + + private Set getMigrations() { + TreeSet migrations = getAllMigrations(); + if (migrations.isEmpty()) { + log.warn("No migration file was found!"); + return Collections.emptySet(); + } + // query migration histories + TreeSet migrationHistories = new TreeSet<>( + jdbcTemplate.query("select * from migration_history", new BeanPropertyRowMapper<>(Migration.class))); + // filter the migrations that need to do + Set migrationsToDo; + if (CollectionUtils.isEmpty(migrationHistories)) { + return migrations; + } else { + Migration lastMigration = migrationHistories.last(); + migrationsToDo = migrations.tailSet(lastMigration, !lastMigration.isSuccess()); + } + return migrationsToDo; } - return false; - } - - private void prepareMigrationTable() { - List tables = jdbcTemplate.queryForList("SHOW TABLES", String.class); - if (!tables.contains(MIGRATION_TABLE_NAME)) { - jdbcTemplate.execute(TABLE_CREATE_SQL); + + private RuntimeException doMigrations(TreeSet migrations) { + for (Migration migration : migrations) { + log.info("start migration, version: " + migration.getVersion()); + migration.setExecuteUser(username); + migration.setExecuteDate(new Date()); + migration.setSuccess(doMigration(migration)); + upsertMigration(migration); + if (!migration.isSuccess()) { + return new RuntimeException("Migration break at version " + migration.getVersion()); + } else { + log.info("Migration success! version: " + migration.getVersion()); + } + } + log.info("The migration is complete , The latest database version is " + migrations.last().getVersion()); + return null; } - } - - private synchronized TreeSet getAllMigrations() { - TreeSet allMigrations = new TreeSet<>(); - // load migration files - Resource[] resources; - try { - resources = new PathMatchingResourcePatternResolver().getResources(ResourceUtils.CLASSPATH_URL_PREFIX + "db/migration/**/*.sql"); - } catch (IOException e) { - return allMigrations; + + private boolean doMigration(Migration migration) { + + Resource ddlFile = migration.getUpgradeDDLFile(), dmlFile = migration.getUpgradeDMLFile(); + if (runScript(ddlFile, true) && runScript(dmlFile, true)) { + return true; + } + log.error("Migration failure! version: " + migration.getVersion() + ". A rollback is about to be performed"); + Resource rollbackFile = migration.getRollbackFile(); + if (rollbackFile != null) { + runScript(rollbackFile, false); + log.info("The rollback script (" + rollbackFile.getFilename() + ") is successfully executed"); + } else { + log.warn("The rollback script does not exist. Skip execution"); + } + return false; } - File home = new File(FileUtils.concatPath(System.getProperty("user.dir"), MIGRATION_HOME)); - if (home.exists() && home.isDirectory()) { - List sqlFiles = FileUtil.loopFiles(home ,pathname -> - "sql".equals(FileUtil.getSuffix(pathname.getName())) - ); - if (sqlFiles != null) { - resources = sqlFiles.stream().map(FileSystemResource::new).toArray(Resource[]::new); - } + + private void prepareMigrationTable() { + List tables = jdbcTemplate.queryForList("SHOW TABLES", String.class); + if (!tables.contains(MIGRATION_TABLE_NAME)) { + jdbcTemplate.execute(TABLE_CREATE_SQL); + } } - Map> resourceMap = Arrays.stream(resources) - .filter(Migration::isMigrationFile) - .collect(Collectors.groupingBy(r -> Objects.requireNonNull(r.getFilename()).substring(1, r.getFilename().indexOf(SPLIT)))); - - for (Map.Entry> entries : resourceMap.entrySet()) { - Resource ddl = null, dml = null, rollback = null; - for (Resource resource : entries.getValue()) { - String fileName = FileUtil.mainName(Objects.requireNonNull(resource.getFilename())); - if (fileName.startsWith(ScriptType.UPGRADE.getPrefix())) { - String[] extracts = fileName.split(SPLIT); - if ("DDL".equals(extracts[1])) { - ddl = resource; - } else if ("DML".equals(extracts[1])) { - dml = resource; - } - } else if (fileName.startsWith(ScriptType.ROLLBACK.getPrefix())) { - rollback = resource; + + private synchronized TreeSet getAllMigrations() { + TreeSet allMigrations = new TreeSet<>(); + // load migration files + Resource[] resources; + try { + resources = new PathMatchingResourcePatternResolver() + .getResources(ResourceUtils.CLASSPATH_URL_PREFIX + "db/migration/**/*.sql"); + } catch (IOException e) { + return allMigrations; } - } - if (ddl != null || dml != null) { - Migration migration = new Migration(entries.getKey(), ddl, dml, rollback); - if (!allMigrations.add(migration)) { - throw new RuntimeException("Duplicate version " + migration.getVersion()); + File home = new File(FileUtils.concatPath(System.getProperty("user.dir"), MIGRATION_HOME)); + if (home.exists() && home.isDirectory()) { + List sqlFiles = + FileUtil.loopFiles(home, pathname -> "sql".equals(FileUtil.getSuffix(pathname.getName()))); + if (sqlFiles != null) { + resources = sqlFiles.stream().map(FileSystemResource::new).toArray(Resource[]::new); + } } - } - } - return allMigrations; - } - - private void upsertMigration(Migration migration) { - SQL query = new SQL(); - query.SELECT("*").FROM(MIGRATION_TABLE_NAME) - .WHERE("`version` = '" + migration.getVersion() + "'"); - List migrations = jdbcTemplate.query(query.toString(), new BeanPropertyRowMapper<>(Migration.class)); - SQL sql = new SQL(); - if (!CollectionUtils.isEmpty(migrations) && !migrations.get(0).isSuccess()) { - sql.UPDATE(MIGRATION_TABLE_NAME) - .SET("success = " + String.format("'%s'", (migration.isSuccess() ? "1" : "0")) - , "execute_date = " + String.format("'%s'", DateFormatUtils.format(new Date(), DEFAULT_DATE_FORMAT))) - .WHERE("`version` = " + String.format("'%s'", migration.getVersion())); - } else { - sql.INSERT_INTO(MIGRATION_TABLE_NAME) - .INTO_VALUES(String.format("'%s'", migration.getVersion()) - , String.format("'%s'", migration.getExecuteUser()) - , String.format("'%s'", DateFormatUtils.format(migration.getExecuteDate(), DEFAULT_DATE_FORMAT)) - , String.format("'%s'", migration.isSuccess() ? "1" : "0")); + Map> resourceMap = Arrays.stream(resources) + .filter(Migration::isMigrationFile) + .collect(Collectors.groupingBy( + r -> Objects.requireNonNull(r.getFilename()).substring(1, r.getFilename().indexOf(SPLIT)))); + + for (Map.Entry> entries : resourceMap.entrySet()) { + Resource ddl = null, dml = null, rollback = null; + for (Resource resource : entries.getValue()) { + String fileName = FileUtil.mainName(Objects.requireNonNull(resource.getFilename())); + if (fileName.startsWith(ScriptType.UPGRADE.getPrefix())) { + String[] extracts = fileName.split(SPLIT); + if ("DDL".equals(extracts[1])) { + ddl = resource; + } else if ("DML".equals(extracts[1])) { + dml = resource; + } + } else if (fileName.startsWith(ScriptType.ROLLBACK.getPrefix())) { + rollback = resource; + } + } + if (ddl != null || dml != null) { + Migration migration = new Migration(entries.getKey(), ddl, dml, rollback); + if (!allMigrations.add(migration)) { + throw new RuntimeException("Duplicate version " + migration.getVersion()); + } + } + } + return allMigrations; } - jdbcTemplate.execute(sql.toString()); - } - - private boolean runScript(Resource resource, boolean stopOnError) { - try (Connection connection = DriverManager.getConnection(url, username, password)) { - ScriptRunner scriptRunner = new ScriptRunner(connection); - scriptRunner.setAutoCommit(false); - scriptRunner.setStopOnError(stopOnError); - scriptRunner.setSendFullScript(false); - LogWriter logWriter = new LogWriter(System.out); - if (!stopOnError) { - scriptRunner.setErrorLogWriter(logWriter); - } - scriptRunner.setLogWriter(logWriter); - scriptRunner.runScript(new InputStreamReader(resource.getInputStream())); - return true; - } catch (Exception e) { - log.error("Script execute failed! " + resource.getFilename(), e); - return false; + + private void upsertMigration(Migration migration) { + SQL query = new SQL(); + query.SELECT("*").FROM(MIGRATION_TABLE_NAME) + .WHERE("`version` = '" + migration.getVersion() + "'"); + List migrations = jdbcTemplate.query(query.toString(), new BeanPropertyRowMapper<>(Migration.class)); + SQL sql = new SQL(); + if (!CollectionUtils.isEmpty(migrations) && !migrations.get(0).isSuccess()) { + sql.UPDATE(MIGRATION_TABLE_NAME) + .SET("success = " + String.format("'%s'", (migration.isSuccess() ? "1" : "0")), + "execute_date = " + + String.format("'%s'", DateFormatUtils.format(new Date(), DEFAULT_DATE_FORMAT))) + .WHERE("`version` = " + String.format("'%s'", migration.getVersion())); + } else { + sql.INSERT_INTO(MIGRATION_TABLE_NAME) + .INTO_VALUES(String.format("'%s'", migration.getVersion()), + String.format("'%s'", migration.getExecuteUser()), + String.format("'%s'", + DateFormatUtils.format(migration.getExecuteDate(), DEFAULT_DATE_FORMAT)), + String.format("'%s'", migration.isSuccess() ? "1" : "0")); + } + jdbcTemplate.execute(sql.toString()); } - } - - private void printCurrentVersion() { - String currentVersion = null, lastVersion = null; - TreeSet migrations = queryMigrationHistory(); - if (!CollectionUtils.isEmpty(migrations)) { - Migration last = migrations.last(); - while (last != null && !last.isSuccess()) { - last = migrations.lower(last); - } - if (last != null) { - currentVersion = last.getVersion(); - } + + private boolean runScript(Resource resource, boolean stopOnError) { + try (Connection connection = DriverManager.getConnection(url, username, password)) { + ScriptRunner scriptRunner = new ScriptRunner(connection); + scriptRunner.setAutoCommit(false); + scriptRunner.setStopOnError(stopOnError); + scriptRunner.setSendFullScript(false); + LogWriter logWriter = new LogWriter(System.out); + if (!stopOnError) { + scriptRunner.setErrorLogWriter(logWriter); + } + scriptRunner.setLogWriter(logWriter); + scriptRunner.runScript(new InputStreamReader(resource.getInputStream())); + return true; + } catch (Exception e) { + log.error("Script execute failed! " + resource.getFilename(), e); + return false; + } } - - TreeSet allMigrations = getAllMigrations(); - if (CollUtil.isEmpty(allMigrations)) { - return; + + private void printCurrentVersion() { + String currentVersion = null, lastVersion = null; + TreeSet migrations = queryMigrationHistory(); + if (!CollectionUtils.isEmpty(migrations)) { + Migration last = migrations.last(); + while (last != null && !last.isSuccess()) { + last = migrations.lower(last); + } + if (last != null) { + currentVersion = last.getVersion(); + } + } + + TreeSet allMigrations = getAllMigrations(); + if (CollUtil.isEmpty(allMigrations)) { + return; + } + lastVersion = allMigrations.last().getVersion(); + log.info("Last Script Version {}, Current Database Version {}", lastVersion, currentVersion); } - lastVersion = allMigrations.last().getVersion(); - log.info("Last Script Version {}, Current Database Version {}", lastVersion, currentVersion); - } - - private TreeSet queryMigrationHistory() { - return new TreeSet<>(jdbcTemplate.query("select * from migration_history", new BeanPropertyRowMapper<>(Migration.class))); - } - - static class LogWriter extends PrintWriter { - - public LogWriter(OutputStream out) { - super(out); + + private TreeSet queryMigrationHistory() { + return new TreeSet<>( + jdbcTemplate.query("select * from migration_history", new BeanPropertyRowMapper<>(Migration.class))); } - - @Override - public void write(String s) { - log.info(s); + + static class LogWriter extends PrintWriter { + + public LogWriter(OutputStream out) { + super(out); + } + + @Override + public void write(String s) { + log.info(s); + } } - } - -} \ No newline at end of file + +} diff --git a/datasophon-api/src/main/java/com/datasophon/api/migration/Migration.java b/datasophon-api/src/main/java/com/datasophon/api/migration/Migration.java index 27f8c96a..1c648707 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/migration/Migration.java +++ b/datasophon-api/src/main/java/com/datasophon/api/migration/Migration.java @@ -21,83 +21,85 @@ import static com.datasophon.api.migration.DatabaseMigration.SPLIT; +import org.apache.commons.lang3.StringUtils; + import java.util.Arrays; import java.util.Date; import java.util.Objects; + import lombok.Data; import lombok.NoArgsConstructor; -import org.apache.commons.lang3.StringUtils; + import org.springframework.core.io.Resource; @Data @NoArgsConstructor public class Migration implements Comparable { - - private String version; - - private String executeUser; - - private Date executeDate; - - private boolean success; - - private Resource upgradeDDLFile; - - private Resource upgradeDMLFile; - - private Resource rollbackFile; - - public Migration(String version, Resource upgradeDDLFile, Resource upgradeDMLFile, Resource rollbackFile) { - this.version = version; - this.upgradeDDLFile = upgradeDDLFile; - this.upgradeDMLFile = upgradeDMLFile; - this.rollbackFile = rollbackFile; - } - - @Override - public int compareTo(Migration other) { - int[] otherId = Arrays.stream(other.getVersion().split("\\.")).mapToInt(Integer::valueOf).toArray(); - int[] thisId = Arrays.stream(version.split("\\.")).mapToInt(Integer::valueOf).toArray(); - if (otherId.length != thisId.length) { - return thisId.length - otherId.length; - } - for (int i = 0; i < thisId.length; i++) { - if (thisId[i] != otherId[i]) { - return thisId[i] - otherId[i]; - } + + private String version; + + private String executeUser; + + private Date executeDate; + + private boolean success; + + private Resource upgradeDDLFile; + + private Resource upgradeDMLFile; + + private Resource rollbackFile; + + public Migration(String version, Resource upgradeDDLFile, Resource upgradeDMLFile, Resource rollbackFile) { + this.version = version; + this.upgradeDDLFile = upgradeDDLFile; + this.upgradeDMLFile = upgradeDMLFile; + this.rollbackFile = rollbackFile; } - return 0; - } - - - public static boolean isMigrationFile(Resource resource) { - if (resource == null) { - return false; + + @Override + public int compareTo(Migration other) { + int[] otherId = Arrays.stream(other.getVersion().split("\\.")).mapToInt(Integer::valueOf).toArray(); + int[] thisId = Arrays.stream(version.split("\\.")).mapToInt(Integer::valueOf).toArray(); + if (otherId.length != thisId.length) { + return thisId.length - otherId.length; + } + for (int i = 0; i < thisId.length; i++) { + if (thisId[i] != otherId[i]) { + return thisId[i] - otherId[i]; + } + } + return 0; } - String name = resource.getFilename(); - if (!StringUtils.endsWithIgnoreCase(name, ".sql")) { - return false; + + public static boolean isMigrationFile(Resource resource) { + if (resource == null) { + return false; + } + String name = resource.getFilename(); + if (!StringUtils.endsWithIgnoreCase(name, ".sql")) { + return false; + } + if (name == null || name.split(SPLIT).length != 2) { + return false; + } + return name.startsWith(ScriptType.ROLLBACK.getPrefix()) || name.startsWith(ScriptType.UPGRADE.getPrefix()); } - if (name == null || name.split(SPLIT).length != 2) { - return false; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Migration)) { + return false; + } + Migration migration = (Migration) o; + return version.equals(migration.version); } - return name.startsWith(ScriptType.ROLLBACK.getPrefix()) || name.startsWith(ScriptType.UPGRADE.getPrefix()); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; + + @Override + public int hashCode() { + return Objects.hash(version); } - if (!(o instanceof Migration)) { - return false; - } - Migration migration = (Migration) o; - return version.equals(migration.version); - } - - @Override - public int hashCode() { - return Objects.hash(version); - } -} \ No newline at end of file +} diff --git a/datasophon-api/src/main/java/com/datasophon/api/migration/ScriptType.java b/datasophon-api/src/main/java/com/datasophon/api/migration/ScriptType.java index 5757db1b..187e9bec 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/migration/ScriptType.java +++ b/datasophon-api/src/main/java/com/datasophon/api/migration/ScriptType.java @@ -19,22 +19,23 @@ package com.datasophon.api.migration; -import lombok.Getter; import org.apache.commons.lang3.StringUtils; +import lombok.Getter; + @Getter public enum ScriptType { - + UPGRADE("V"), - + ROLLBACK("R"); - + private final String prefix; - + ScriptType(String prefix) { this.prefix = prefix; } - + public static ScriptType of(String version) { if (StringUtils.isBlank(version)) { return null; diff --git a/datasophon-api/src/main/java/com/datasophon/api/security/AuthenticationType.java b/datasophon-api/src/main/java/com/datasophon/api/security/AuthenticationType.java index faeae096..386acbff 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/security/AuthenticationType.java +++ b/datasophon-api/src/main/java/com/datasophon/api/security/AuthenticationType.java @@ -23,15 +23,15 @@ * authentication type */ public enum AuthenticationType { - + PASSWORD(0, "verify via user name and password"), ; - + AuthenticationType(int code, String desc) { this.code = code; this.desc = desc; } - + @EnumValue private final int code; private final String desc; diff --git a/datasophon-api/src/main/java/com/datasophon/api/security/Authenticator.java b/datasophon-api/src/main/java/com/datasophon/api/security/Authenticator.java index 4cf6087d..c3a15919 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/security/Authenticator.java +++ b/datasophon-api/src/main/java/com/datasophon/api/security/Authenticator.java @@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest; public interface Authenticator { - + /** * Verifying legality via username and password * @@ -33,7 +33,7 @@ public interface Authenticator { * @return result object */ Result authenticate(String username, String password, String extra); - + /** * Get authenticated user * diff --git a/datasophon-api/src/main/java/com/datasophon/api/security/PasswordAuthenticator.java b/datasophon-api/src/main/java/com/datasophon/api/security/PasswordAuthenticator.java index 77eb23b4..332f03bf 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/security/PasswordAuthenticator.java +++ b/datasophon-api/src/main/java/com/datasophon/api/security/PasswordAuthenticator.java @@ -35,14 +35,14 @@ import org.springframework.beans.factory.annotation.Autowired; public class PasswordAuthenticator implements Authenticator { - + private static final Logger logger = LoggerFactory.getLogger(PasswordAuthenticator.class); - + @Autowired private UserInfoService userService; @Autowired private SessionService sessionService; - + @Override public Result authenticate(String username, String password, String extra) { Result result = new Result(); @@ -53,7 +53,7 @@ public Result authenticate(String username, String password, String extra) { result.put(Constants.MSG, Status.USER_NAME_PASSWD_ERROR.getMsg()); return result; } - + // create session String sessionId = sessionService.createSession(user, extra); if (sessionId == null) { @@ -69,7 +69,7 @@ public Result authenticate(String username, String password, String extra) { SecurityUtils.getSession().setAttribute(Constants.SESSION_USER, user); return result; } - + @Override public UserInfoEntity getAuthUser(HttpServletRequest request) { SessionEntity session = sessionService.getSession(request); diff --git a/datasophon-api/src/main/java/com/datasophon/api/security/SecurityConfig.java b/datasophon-api/src/main/java/com/datasophon/api/security/SecurityConfig.java index 214b0d49..0bba70b6 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/security/SecurityConfig.java +++ b/datasophon-api/src/main/java/com/datasophon/api/security/SecurityConfig.java @@ -17,7 +17,7 @@ package com.datasophon.api.security; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,30 +29,30 @@ @Configuration public class SecurityConfig { - + private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class); - + @Value("${security.authentication.type:PASSWORD}") private String type; - + private AutowireCapableBeanFactory beanFactory; private AuthenticationType authenticationType; - + @Autowired public SecurityConfig(AutowireCapableBeanFactory beanFactory) { this.beanFactory = beanFactory; } - + private void setAuthenticationType(String type) { if (StringUtils.isBlank(type)) { logger.info("security.authentication.type configuration is empty, the default value 'PASSWORD'"); this.authenticationType = AuthenticationType.PASSWORD; return; } - + this.authenticationType = AuthenticationType.valueOf(type); } - + @Bean(name = "authenticator") public Authenticator authenticator() { setAuthenticationType(type); diff --git a/datasophon-api/src/main/java/com/datasophon/api/security/UserPermission.java b/datasophon-api/src/main/java/com/datasophon/api/security/UserPermission.java index 6ae2b8f8..1f13793d 100644 --- a/datasophon-api/src/main/java/com/datasophon/api/security/UserPermission.java +++ b/datasophon-api/src/main/java/com/datasophon/api/security/UserPermission.java @@ -26,5 +26,5 @@ @Retention(RUNTIME) @Target(METHOD) public @interface UserPermission { - + } diff --git a/datasophon-api/src/main/resources/meta/DDP-1.2.2/DORIS/service_ddl.json b/datasophon-api/src/main/resources/meta/DDP-1.2.2/DORIS/service_ddl.json index 68b4d48f..3f89fd89 100644 --- a/datasophon-api/src/main/resources/meta/DDP-1.2.2/DORIS/service_ddl.json +++ b/datasophon-api/src/main/resources/meta/DDP-1.2.2/DORIS/service_ddl.json @@ -367,4 +367,5 @@ "defaultValue": "" } ] -} \ No newline at end of file +} + diff --git a/datasophon-common/pom.xml b/datasophon-common/pom.xml index ae0473f5..ee36bb8f 100644 --- a/datasophon-common/pom.xml +++ b/datasophon-common/pom.xml @@ -38,8 +38,8 @@ guava - commons-lang - commons-lang + org.apache.commons + commons-lang3 ch.qos.logback @@ -88,116 +88,116 @@ ${hadoop.version} - jetty-util org.mortbay.jetty + jetty-util - jetty org.mortbay.jetty + jetty org.mortbay.jetty jetty-sslengine - jasper-compiler tomcat + jasper-compiler - apacheds-kerberos-codec org.apache.directory.server + apacheds-kerberos-codec - servlet-api javax.servlet + servlet-api - jsp-api javax.servlet.jsp + jsp-api - jets3t net.java.dev.jets3t + jets3t - jasper-runtime tomcat + jasper-runtime - avro org.apache.avro + avro - httpcore org.apache.httpcomponents + httpcore - hadoop-auth org.apache.hadoop + hadoop-auth - activation javax.activation + activation - slf4j-api org.slf4j + slf4j-api - guava com.google.guava + guava - commons-cli commons-cli + commons-cli - jersey-server com.sun.jersey + jersey-server - jersey-json com.sun.jersey + jersey-json - jersey-core com.sun.jersey + jersey-core - jackson-core-asl org.codehaus.jackson + jackson-core-asl - jackson-mapper-asl org.codehaus.jackson + jackson-mapper-asl - slf4j-log4j12 org.slf4j + slf4j-log4j12 - commons-logging commons-logging + commons-logging - httpclient org.apache.httpcomponents + httpclient - commons-lang commons-lang + commons-lang - jsch com.jcraft + jsch - slf4j-reload4j org.slf4j + slf4j-reload4j - reload4j ch.qos.reload4j + reload4j @@ -207,40 +207,40 @@ ${hadoop.version} - apacheds-kerberos-codec org.apache.directory.server + apacheds-kerberos-codec - slf4j-log4j12 org.slf4j + slf4j-log4j12 - log4j log4j + log4j - httpclient org.apache.httpcomponents + httpclient - slf4j-api org.slf4j + slf4j-api - guava com.google.guava + guava - nimbus-jose-jwt com.nimbusds + nimbus-jose-jwt - reload4j ch.qos.reload4j + reload4j - slf4j-reload4j org.slf4j + slf4j-reload4j diff --git a/datasophon-common/src/main/java/com/datasophon/common/Constants.java b/datasophon-common/src/main/java/com/datasophon/common/Constants.java index 6bc8207a..baa13418 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/Constants.java +++ b/datasophon-common/src/main/java/com/datasophon/common/Constants.java @@ -25,32 +25,32 @@ * Constants */ public final class Constants { - + public static final String INSTALL_PATH = PropertyUtils.getString("install.path"); public static final String DATA = "data"; public static final String INSTALL_TYPE = "install_type"; public static final String TOTAL = "total"; - + public static final String DATASOPHON = "datasophon"; - + public static final String HOST_MAP = "_host_map"; public static final String COMMAND_HOST_ID = "command_host_id"; public static final String HOST_MD5 = "_host_md5"; public static final String ID_RSA = PropertyUtils.getString("id_rsa", "/.ssh/id_rsa"); public static final String HOSTNAME = "hostname"; - + public static final String MASTER_MANAGE_PACKAGE_PATH = INSTALL_PATH + "/DDP/packages"; public static final String UNZIP_DDH_WORKER_CMD = "tar -zxvf " + INSTALL_PATH + "/datasophon-worker.tar.gz -C " + INSTALL_PATH; public static final String START_DDH_WORKER_CMD = "service datasophon-worker restart"; - + public static final String WORKER_PACKAGE_NAME = "datasophon-worker.tar.gz"; public static final String WORKER_SCRIPT_PATH = INSTALL_PATH + "/datasophon-worker/script/"; public static final String WORKER_PATH = INSTALL_PATH + "/datasophon-worker"; public static final String SHELL_SCRIPT_PATH = "/scripts"; - + public static final String META_PATH = "meta"; - + public static final String CLUSTER_ID = "cluster_id"; public static final String MANAGED = "managed"; public static final String JSON = "json"; @@ -78,9 +78,9 @@ public final class Constants { public static final String UPDATE_COMMON_CMD = "sh " + INSTALL_PATH + "/datasophon-worker/script/sed_common.sh "; public static final String MASTER_HOST = "masterHost"; public static final String MASTER_WEB_PORT = "masterWebPort"; - + public static final String HOST_COMMAND_ID = "host_command_id"; - + public static final String CONFIG_VERSION = "config_version"; public static final String HAS_EN = ".*[a-zA-z].*"; public static final String ALERT_TARGET_NAME = "alert_target_name"; @@ -91,7 +91,7 @@ public final class Constants { public static final String MULTIPLE = "multiple"; public static final String CLUSTER_STATE = "cluster_state"; public static final String PATH = "path"; - + public static final String MV_PATH = "mv_path"; public static final String SERVICE_INSTANCE_ID = "service_instance_id"; public static final String IS_ENABLED = "is_enabled"; @@ -109,7 +109,7 @@ public final class Constants { public static final String ROLE_GROUP_ID = "role_group_id"; public static final String ROLE_GROUP_TYPE = "role_group_type"; public static final String NEET_RESTART = "need_restart"; - + public static final String CPU_ARCHITECTURE = "cpu_architecture"; public static final String HOST_STATE = "host_state"; public static final String FAILED = "failed"; @@ -122,45 +122,45 @@ public final class Constants { public static final String RACK = "rack"; public static final String SERVICE_STATE = "service_state"; public static final String EQUAL_SIGN = "="; - + private Constants() { throw new IllegalStateException("Constants Exception"); } - + public static final String USERNAME = "username"; - + public static final String PASSWORD = "password"; /** * session user */ public static final String SESSION_USER = "session.user"; - + public static final String SESSION_ID = "sessionId"; /** * session timeout */ public static final int SESSION_TIME_OUT = 7200; - + /** * http header */ public static final String HTTP_HEADER_UNKNOWN = "unKnown"; - + /** * http X-Forwarded-For */ public static final String HTTP_X_FORWARDED_FOR = "X-Forwarded-For"; - + /** * http X-Real-IP */ public static final String HTTP_X_REAL_IP = "X-Real-IP"; - + /** * UTF-8 */ public static final String UTF_8 = "UTF-8"; - + /** * user name regex */ @@ -169,17 +169,17 @@ private Constants() { * comma , */ public static final String COMMA = ","; - + /** * slash / */ public static final String SLASH = "/"; - + /** * SPACE " " */ public static final String SPACE = " "; - + /** * SINGLE_SLASH / */ @@ -188,68 +188,69 @@ private Constants() { * status */ public static final String STATUS = "status"; - + /** * message */ public static final String MSG = "msg"; - + public static final String REGEX_VARIABLE = "\\$\\{(.*?)\\}"; - + /** * email regex */ public static final Pattern REGEX_MAIL_NAME = Pattern.compile("^([a-z0-9A-Z]+[_|\\-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"); - + /** * 常量-数值100 */ public static final int ONE_HUNDRRD = 100; - + /** * 常量-数值200 */ public static final int TWO_HUNDRRD = 200; - + /** * 常量-数值10 */ public static final int TEN = 10; - + /** * 常量-zkserver */ public static final String ZKSERVER = "zkserver"; - + public static final String CENTER_BRACKET_LEFT = "["; - + public static final String CENTER_BRACKET_RIGHT = "]"; /** * 常量-连接号 */ public static final String HYPHEN = "-"; - + public static final String TASK_MANAGER = "taskmanager"; public static final String JOB_MANAGER = "jobmanager"; - public static final String x86_64 = "x86_64"; + public static final String X86_64 = "x86_64"; + public static final String PROMETHEUS = "prometheus"; - + public static final String XML = "xml"; public static final String PROPERTIES = "properties"; public static final String PROPERTIES2 = "properties2"; public static final String PROPERTIES3 = "properties3"; - + /** * os name properties */ public static final String OSNAME_PROPERTIES = "os.name"; - + /** * windows os name */ public static final String OSNAME_WINDOWS = "Windows"; - + /** * windows hosts file basedir */ @@ -258,6 +259,6 @@ private Constants() { * root user */ public static final String ROOT = "root"; - + public static final String DISPATCHER_WORK = "dispatcher-worker.sh"; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/cache/CacheUtils.java b/datasophon-common/src/main/java/com/datasophon/common/cache/CacheUtils.java index e0b5d3e7..af209914 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/cache/CacheUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/cache/CacheUtils.java @@ -27,40 +27,40 @@ * Cache工具类 */ public class CacheUtils { - + private static Logger logger = LoggerFactory.getLogger(CacheUtils.class); private static Cache cache = CacheUtil.newLRUCache(4096); - + public static Object get(String key) { Object data = cache.get(key); return data; - }; - + } + public static void put(String key, Object value) { cache.put(key, value); } - + public static boolean constainsKey(String key) { return cache.containsKey(key); } - + public static void removeKey(String key) { cache.remove(key); } - + public static Integer getInteger(String key) { Object data = cache.get(key); return (Integer) data; } - + public static Boolean getBoolean(String key) { Object data = cache.get(key); return (Boolean) data; } - + public static String getString(String key) { Object data = cache.get(key); return (String) data; } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommand.java index 2d42e50e..a786455b 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommand.java @@ -26,28 +26,28 @@ @Data public class BaseCommand implements Serializable { - + private static final long serialVersionUID = -1495156573211152639L; - + private String frameCode; - + private String serviceName; - + private String serviceRoleName; - + private ServiceRoleType serviceRoleType; - + private String hostCommandId; - + private String packageName; - + private Integer clusterId; - + private ServiceRoleRunner startRunner; - + private ServiceRoleRunner stopRunner; - + private ServiceRoleRunner statusRunner; - + private ServiceRoleRunner restartRunner; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommandResult.java b/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommandResult.java index c2a84448..2615adba 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommandResult.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/BaseCommandResult.java @@ -23,8 +23,8 @@ @Data public class BaseCommandResult implements Serializable { - + private Boolean execResult; - + private String execOut; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/CheckCommandExecuteProgressCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/CheckCommandExecuteProgressCommand.java index 79560754..f688bfbf 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/CheckCommandExecuteProgressCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/CheckCommandExecuteProgressCommand.java @@ -27,11 +27,11 @@ @Data public class CheckCommandExecuteProgressCommand { - + private List serviceRoleInfoList; - + private Map completeTaskList; - + public CheckCommandExecuteProgressCommand(Map completeTaskList, List serviceRoleInfoList) { this.completeTaskList = completeTaskList; diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/CheckServiceExecuteStateCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/CheckServiceExecuteStateCommand.java index d93d4065..1792af0a 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/CheckServiceExecuteStateCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/CheckServiceExecuteStateCommand.java @@ -26,11 +26,11 @@ @Data public class CheckServiceExecuteStateCommand implements Serializable { - + private ServiceNode serviceNode; - + private ServiceRoleType serviceRoleType; - + public CheckServiceExecuteStateCommand(ServiceNode serviceNode, ServiceRoleType serviceRoleType) { this.serviceNode = serviceNode; this.serviceRoleType = serviceRoleType; diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/ClusterCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/ClusterCommand.java index b8b47627..55684d0f 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/ClusterCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/ClusterCommand.java @@ -25,18 +25,18 @@ @Data public class ClusterCommand implements Serializable { - + private final ClusterCommandType commandType; - + private Integer clusterId; - + public ClusterCommand(ClusterCommandType commandType) { this.commandType = commandType; } - + public ClusterCommand(ClusterCommandType commandType, Integer clusterId) { this.commandType = commandType; this.clusterId = clusterId; } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/DispatcherHostAgentCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/DispatcherHostAgentCommand.java index d06fc1dc..935c6413 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/DispatcherHostAgentCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/DispatcherHostAgentCommand.java @@ -23,13 +23,13 @@ @Data public class DispatcherHostAgentCommand { - + private HostInfo hostInfo; - + private Integer clusterId; - + private String clusterFrame; - + public DispatcherHostAgentCommand(HostInfo hostInfo, Integer clusterId, String clusterFrame) { this.hostInfo = hostInfo; this.clusterId = clusterId; diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteCmdCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteCmdCommand.java index 6d7a9187..ead54c79 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteCmdCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteCmdCommand.java @@ -24,10 +24,10 @@ @Data public class ExecuteCmdCommand implements Serializable { - + private static final long serialVersionUID = 8665156195475027337L; - + private List commands; - + private String commandLine; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteServiceRoleCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteServiceRoleCommand.java index 104f413f..5db8be89 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteServiceRoleCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/ExecuteServiceRoleCommand.java @@ -31,34 +31,34 @@ @Data public class ExecuteServiceRoleCommand { - + private Integer clusterId; - + private String clusterCode; - + private String serviceName; - + private List masterRoles; - + private ServiceRoleInfo workerRole; - + private ServiceRoleType serviceRoleType; - + private CommandType commandType; - + private DAGGraph dag; - + private Map errorTaskList; private Map activeTaskList; private Map readyToSubmitTaskList; private Map completeTaskList; - + public ExecuteServiceRoleCommand(Integer clusterId, String serviceName, List serviceRoles) { this.clusterId = clusterId; this.serviceName = serviceName; this.masterRoles = serviceRoles; } - + public ExecuteServiceRoleCommand() { } } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/FileOperateCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/FileOperateCommand.java index de86c1c2..0e097012 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/FileOperateCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/FileOperateCommand.java @@ -24,10 +24,10 @@ @Data public class FileOperateCommand implements Serializable { - + private TreeSet lines; - + private String content; - + private String path; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateAlertConfigCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateAlertConfigCommand.java index a6ca6f2f..fd56a3b2 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateAlertConfigCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateAlertConfigCommand.java @@ -28,7 +28,7 @@ @Data public class GenerateAlertConfigCommand implements Serializable { - + HashMap> configFileMap; Integer clusterId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateHostPrometheusConfig.java b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateHostPrometheusConfig.java index 4306b5f4..36fa5c66 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateHostPrometheusConfig.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateHostPrometheusConfig.java @@ -23,6 +23,6 @@ @Data public class GenerateHostPrometheusConfig implements Serializable { - + private Integer clusterId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GeneratePrometheusConfigCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/GeneratePrometheusConfigCommand.java index 9fefa301..fd99b61b 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GeneratePrometheusConfigCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GeneratePrometheusConfigCommand.java @@ -25,11 +25,11 @@ @Data @Accessors(chain = true) public class GeneratePrometheusConfigCommand implements Serializable { - + private Integer serviceInstanceId; - + private String clusterFrame; - + private Integer clusterId; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateRackPropCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateRackPropCommand.java index 7e4870e3..909d80ac 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateRackPropCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateRackPropCommand.java @@ -20,9 +20,10 @@ import java.io.Serializable; import lombok.Data; + @Data public class GenerateRackPropCommand implements Serializable { - + private Integer clusterId; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateSRPromConfigCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateSRPromConfigCommand.java index be839b72..e6f98b7a 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateSRPromConfigCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateSRPromConfigCommand.java @@ -23,13 +23,13 @@ @Data public class GenerateSRPromConfigCommand implements Serializable { - + private Integer serviceInstanceId; - + private String clusterFrame; - + private Integer clusterId; - + private String filename; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateServiceConfigCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateServiceConfigCommand.java index 9021f1b1..9407ba4b 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateServiceConfigCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateServiceConfigCommand.java @@ -29,18 +29,18 @@ @Data public class GenerateServiceConfigCommand implements Serializable { - + private static final long serialVersionUID = -4211566568993105684L; - + private String serviceName; - + private String decompressPackageName; - + private Integer myid; - + Map> cofigFileMap; - + private String serviceRoleName; - + private RunAs runAs; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateStarRocksHAMessage.java b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateStarRocksHAMessage.java index f60e0217..e7992558 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GenerateStarRocksHAMessage.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GenerateStarRocksHAMessage.java @@ -23,8 +23,8 @@ @Data public class GenerateStarRocksHAMessage implements Serializable { - + private Integer serviceInstanceId; - + private Integer clusterId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/GetLogCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/GetLogCommand.java index 8751eaff..439e62db 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/GetLogCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/GetLogCommand.java @@ -23,9 +23,9 @@ @Data public class GetLogCommand implements Serializable { - + private String logFile; - + private String decompressPackageName; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/HdfsEcCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/HdfsEcCommand.java index fb1d0ea8..786d29ff 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/HdfsEcCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/HdfsEcCommand.java @@ -23,6 +23,6 @@ @Data public class HdfsEcCommand implements Serializable { - + private Integer serviceInstanceId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/HostCheckCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/HostCheckCommand.java index bf195108..2c203c3c 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/HostCheckCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/HostCheckCommand.java @@ -23,16 +23,16 @@ @Data public class HostCheckCommand { - + private HostInfo hostInfo; - + private String clusterCode; - + public HostCheckCommand(HostInfo hostInfo, String clusterCode) { this.hostInfo = hostInfo; this.clusterCode = clusterCode; } - + public HostCheckCommand() { } } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/HostInfoCollectResult.java b/datasophon-common/src/main/java/com/datasophon/common/command/HostInfoCollectResult.java index 82afa5b1..bd67dc03 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/HostInfoCollectResult.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/HostInfoCollectResult.java @@ -24,7 +24,7 @@ @Data public class HostInfoCollectResult implements Serializable { - + private static final long serialVersionUID = 4197649708954689128L; private int coreNum; private double totalMem; @@ -36,5 +36,5 @@ public class HostInfoCollectResult implements Serializable { private double diskUsedPersent; private double averageLoad; private String clusterCode; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommand.java index 0556deaf..6bd78dae 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommand.java @@ -21,31 +21,32 @@ import com.datasophon.common.model.Generators; import com.datasophon.common.model.RunAs; import com.datasophon.common.model.ServiceConfig; -import lombok.Data; import java.io.Serializable; import java.util.List; import java.util.Map; +import lombok.Data; + @Data public class InstallServiceRoleCommand extends BaseCommand implements Serializable { - + private static final long serialVersionUID = -8610024764701745463L; - + private Map> cofigFileMap; - + private Long deliveryId; - + private Integer normalSize; - + private String packageMd5; - + private String decompressPackageName; - + private RunAs runAs; - + private ServiceRoleType serviceRoleType; - - private List> resourceStrategies; - + + private List> resourceStrategies; + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandConfirm.java b/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandConfirm.java index f448795b..47e21c32 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandConfirm.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandConfirm.java @@ -23,6 +23,6 @@ @Data public class InstallServiceRoleCommandConfirm implements Serializable { - + private Long deliveryId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandResult.java b/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandResult.java index 5812668a..6df29981 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandResult.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/InstallServiceRoleCommandResult.java @@ -23,9 +23,9 @@ @Data public class InstallServiceRoleCommandResult extends BaseCommandResult implements Serializable { - + private static final long serialVersionUID = -2524637560247096696L; private InstallServiceRoleCommand installServiceRoleCommand; - + private Long deliveryId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/OlapOpsType.java b/datasophon-common/src/main/java/com/datasophon/common/command/OlapOpsType.java index 52b8c576..0cfbb7a6 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/OlapOpsType.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/OlapOpsType.java @@ -14,39 +14,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.common.command; public enum OlapOpsType { - + ADD_BE(1, "backend"), ADD_FE_FOLLOWER(2, "follower"), ADD_FE_OBSERVER(3, "observer"); - + private int value; - + private String desc; - + OlapOpsType(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/OlapSqlExecCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/OlapSqlExecCommand.java index bcac2f58..59f3bcc3 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/OlapSqlExecCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/OlapSqlExecCommand.java @@ -6,10 +6,10 @@ @Data public class OlapSqlExecCommand implements Serializable { - + private OlapOpsType opsType; - + private String feMaster; - + private String hostName; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/PingCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/PingCommand.java index c6c36826..b59974fb 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/PingCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/PingCommand.java @@ -17,10 +17,10 @@ package com.datasophon.common.command; -import lombok.Data; - import java.io.Serializable; +import lombok.Data; + /** * * @@ -28,7 +28,7 @@ */ @Data public class PingCommand implements Serializable { - + private String message; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/ServiceCheckCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/ServiceCheckCommand.java index e42b036c..d12158df 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/ServiceCheckCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/ServiceCheckCommand.java @@ -23,8 +23,8 @@ @Data public class ServiceCheckCommand extends BaseCommand implements Serializable { - + private Integer serviceRoleInstanceId; - + private Long deliveryId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommand.java index 7fdc476b..4095aaf0 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommand.java @@ -26,28 +26,28 @@ @Data public class ServiceRoleOperateCommand extends BaseCommand implements Serializable { - + private static final long serialVersionUID = 6454341380133032878L; private Integer serviceRoleInstanceId; - + private CommandType commandType; - + private Long deliveryId; - + private String decompressPackageName; - + private boolean isSlave; - + private String masterHost; - + private String managerHost; - + private Boolean enableRangerPlugin; - + private RunAs runAs; - + private Boolean enableKerberos; - + public ServiceRoleOperateCommand() { this.enableRangerPlugin = false; this.enableKerberos = false; diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommandResult.java b/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommandResult.java index 48c4c758..0cfb194d 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommandResult.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/ServiceRoleOperateCommandResult.java @@ -23,7 +23,7 @@ @Data public class ServiceRoleOperateCommandResult extends BaseCommandResult implements Serializable { - + private static final long serialVersionUID = -566450658744102059L; private ServiceRoleOperateCommand serviceRoleOperateCommand; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/StartExecuteCommandCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/StartExecuteCommandCommand.java index 41ed1b4b..758d44ae 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/StartExecuteCommandCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/StartExecuteCommandCommand.java @@ -26,13 +26,13 @@ @Data public class StartExecuteCommandCommand implements Serializable { - + private List commandIds; - + private Integer clusterId; - + private CommandType commandType; - + public StartExecuteCommandCommand(List list, Integer clusterId, CommandType commandType) { this.commandIds = list; this.clusterId = clusterId; diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/StartScheduledTaskCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/StartScheduledTaskCommand.java index fcaad0ee..7a7c3663 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/StartScheduledTaskCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/StartScheduledTaskCommand.java @@ -20,5 +20,5 @@ import java.io.Serializable; public class StartScheduledTaskCommand implements Serializable { - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/SubmitActiveTaskNodeCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/SubmitActiveTaskNodeCommand.java index fdbc2812..5ce9c6e1 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/SubmitActiveTaskNodeCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/SubmitActiveTaskNodeCommand.java @@ -29,9 +29,9 @@ @Data public class SubmitActiveTaskNodeCommand implements Serializable { - + private static final long serialVersionUID = 3733897759707096649L; - + private CommandType commandType; private Integer clusterId; private String clusterCode; @@ -40,5 +40,5 @@ public class SubmitActiveTaskNodeCommand implements Serializable { private Map activeTaskList; private Map readyToSubmitTaskList; private Map completeTaskList; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixGroupCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixGroupCommand.java index 3bc7bd00..6af19519 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixGroupCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixGroupCommand.java @@ -23,6 +23,6 @@ @Data public class CreateUnixGroupCommand implements Serializable { - + private String groupName; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixUserCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixUserCommand.java index 56941c05..3962b737 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixUserCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/remote/CreateUnixUserCommand.java @@ -23,10 +23,10 @@ @Data public class CreateUnixUserCommand implements Serializable { - + private String username; - + private String mainGroup; - + private String otherGroups; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixGroupCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixGroupCommand.java index b6dfd839..73012cd4 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixGroupCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixGroupCommand.java @@ -23,6 +23,6 @@ @Data public class DelUnixGroupCommand implements Serializable { - + private String groupName; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixUserCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixUserCommand.java index bb2d5d64..b8ea38d8 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixUserCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/remote/DelUnixUserCommand.java @@ -23,7 +23,7 @@ @Data public class DelUnixUserCommand implements Serializable { - + private String username; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/command/remote/GenerateKeytabFileCommand.java b/datasophon-common/src/main/java/com/datasophon/common/command/remote/GenerateKeytabFileCommand.java index 1af64cc9..4d67b0cb 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/command/remote/GenerateKeytabFileCommand.java +++ b/datasophon-common/src/main/java/com/datasophon/common/command/remote/GenerateKeytabFileCommand.java @@ -23,10 +23,10 @@ @Data public class GenerateKeytabFileCommand implements Serializable { - + private String principal; - + private String keytabName; - + private String hostname; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/enums/ClusterCommandType.java b/datasophon-common/src/main/java/com/datasophon/common/enums/ClusterCommandType.java index d7bd696e..6abe7428 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/enums/ClusterCommandType.java +++ b/datasophon-common/src/main/java/com/datasophon/common/enums/ClusterCommandType.java @@ -1,8 +1,8 @@ package com.datasophon.common.enums; public enum ClusterCommandType { - + CHECK, - + DELETE } diff --git a/datasophon-common/src/main/java/com/datasophon/common/enums/CommandType.java b/datasophon-common/src/main/java/com/datasophon/common/enums/CommandType.java index ca13dce8..33d45aec 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/enums/CommandType.java +++ b/datasophon-common/src/main/java/com/datasophon/common/enums/CommandType.java @@ -22,7 +22,7 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum CommandType { - + // 命令类型1:安装服务 2:启动服务 3:停止服务 4:重启服务 5:更新配置后启动 6:更新配置后重启 INSTALL_SERVICE(1, "INSTALL", "安装"), START_SERVICE(2, "START", "启动"), @@ -30,43 +30,44 @@ public enum CommandType { RESTART_SERVICE(4, "RESTART", "重启"), START_WITH_CONFIG(5, "START_WITH_CONFIG", ""), RESTART_WITH_CONFIG(6, "RESTART_WITH_CONFIG", "znDesc"); - + private int value; - + private String desc; - + private String cnDesc; - + CommandType(int value, String desc, String cnDesc) { this.value = value; this.desc = desc; this.cnDesc = cnDesc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + public String getCnDesc() { return cnDesc; } - + public void setZnDesc(String cnDesc) { this.cnDesc = cnDesc; } - + public String getCommandName(String language) { if (Constants.CN.equals(language)) { return this.cnDesc; @@ -74,10 +75,10 @@ public String getCommandName(String language) { return this.desc; } } - + @Override public String toString() { return this.desc; } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/enums/InstallState.java b/datasophon-common/src/main/java/com/datasophon/common/enums/InstallState.java index 27f8ae04..3a751cc6 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/enums/InstallState.java +++ b/datasophon-common/src/main/java/com/datasophon/common/enums/InstallState.java @@ -20,37 +20,38 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum InstallState { - + // 安装状态1:正在安装 2:安装成功 3:安装失败 RUNNING(1, "正在安装"), SUCCESS(2, "安装成功"), FAILED(3, "安装失败"); - + private int value; - + private String desc; - + InstallState(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-common/src/main/java/com/datasophon/common/enums/ReplyType.java b/datasophon-common/src/main/java/com/datasophon/common/enums/ReplyType.java index b417652d..15612300 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/enums/ReplyType.java +++ b/datasophon-common/src/main/java/com/datasophon/common/enums/ReplyType.java @@ -18,7 +18,7 @@ package com.datasophon.common.enums; public enum ReplyType { - + SERVICE_ROLE_STOP, SERVICE_ROLE_START; diff --git a/datasophon-common/src/main/java/com/datasophon/common/enums/ServiceRoleType.java b/datasophon-common/src/main/java/com/datasophon/common/enums/ServiceRoleType.java index 7834e633..e44c4034 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/enums/ServiceRoleType.java +++ b/datasophon-common/src/main/java/com/datasophon/common/enums/ServiceRoleType.java @@ -20,33 +20,33 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum ServiceRoleType { - + MASTER(1, "master"), WORKER(2, "worker"), CLIENT(3, "client"), SLAVE(4, "slave"); - + private Integer code; private String name; - + ServiceRoleType(Integer code, String name) { this.code = code; this.name = name; } - + public Integer getCode() { return code; } - + public void setCode(Integer code) { this.code = code; } - + @JsonValue public String getName() { return name; } - + public void setName(String name) { this.name = name; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/exception/AkkaRemoteException.java b/datasophon-common/src/main/java/com/datasophon/common/exception/AkkaRemoteException.java index c903c2cb..3e8c22ec 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/exception/AkkaRemoteException.java +++ b/datasophon-common/src/main/java/com/datasophon/common/exception/AkkaRemoteException.java @@ -23,9 +23,9 @@ @Data public class AkkaRemoteException implements Serializable { - + private String hostCommandId; - + private String errMsg; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleException.java b/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleException.java index b6b42f70..375917e9 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleException.java +++ b/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleException.java @@ -18,11 +18,11 @@ package com.datasophon.common.lifecycle; public class ServerLifeCycleException extends Exception { - + public ServerLifeCycleException(String message) { super(message); } - + public ServerLifeCycleException(String message, Throwable throwable) { super(message, throwable); } diff --git a/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleManager.java b/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleManager.java index adcfaf10..a14989b1 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleManager.java +++ b/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerLifeCycleManager.java @@ -21,27 +21,27 @@ @UtilityClass public class ServerLifeCycleManager { - + private static volatile ServerStatus serverStatus = ServerStatus.RUNNING; - + private static long serverStartupTime = System.currentTimeMillis(); - + public static long getServerStartupTime() { return serverStartupTime; } - + public static boolean isRunning() { return serverStatus == ServerStatus.RUNNING; } - + public static boolean isStopped() { return serverStatus == ServerStatus.STOPPED; } - + public static ServerStatus getServerStatus() { return serverStatus; } - + /** * Change the current server state to {@link ServerStatus#WAITING}, only {@link ServerStatus#RUNNING} can change to {@link ServerStatus#WAITING}. * @@ -51,13 +51,13 @@ public static synchronized void toWaiting() throws ServerLifeCycleException { if (isStopped()) { throw new ServerLifeCycleException("The current server is already stopped, cannot change to waiting"); } - + if (serverStatus != ServerStatus.RUNNING) { throw new ServerLifeCycleException("The current server is not at running status, cannot change to waiting"); } serverStatus = ServerStatus.WAITING; } - + /** * Recover from {@link ServerStatus#WAITING} to {@link ServerStatus#RUNNING}. * @@ -70,7 +70,7 @@ public static synchronized void recoverFromWaiting() throws ServerLifeCycleExcep serverStartupTime = System.currentTimeMillis(); serverStatus = ServerStatus.RUNNING; } - + public static synchronized boolean toStopped() { if (serverStatus == ServerStatus.STOPPED) { return false; @@ -78,5 +78,5 @@ public static synchronized boolean toStopped() { serverStatus = ServerStatus.STOPPED; return true; } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerStatus.java b/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerStatus.java index ad85e9a9..4b42eb71 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerStatus.java +++ b/datasophon-common/src/main/java/com/datasophon/common/lifecycle/ServerStatus.java @@ -21,24 +21,24 @@ * This enum is used to represent the server status, include master/worker. */ public enum ServerStatus { - + RUNNING(0, "The current server is running"), WAITING(1, "The current server is waiting, this means it cannot work"), STOPPED(2, "The current server is stopped"), ; - + private final int code; private final String desc; - + ServerStatus(int code, String desc) { this.code = code; this.desc = desc; } - + public int getCode() { return code; } - + public String getDesc() { return desc; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/AkkaRemoteReply.java b/datasophon-common/src/main/java/com/datasophon/common/model/AkkaRemoteReply.java index ff2eaeed..b5d0f72b 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/AkkaRemoteReply.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/AkkaRemoteReply.java @@ -22,16 +22,17 @@ import java.io.Serializable; import lombok.Data; + @Data public class AkkaRemoteReply implements Serializable { - + private ReplyType replyType; - + private String hostname; - + private String serviceRoleName; - + private String hostCommandId; - + private String msg; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/AlertItem.java b/datasophon-common/src/main/java/com/datasophon/common/model/AlertItem.java index 0fdecf57..d27abd7e 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/AlertItem.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/AlertItem.java @@ -23,18 +23,18 @@ @Data public class AlertItem implements Serializable { - + private String alertName; - + private Integer clusterId; - + private String alertExpr; - + private String serviceRoleName; - + private String alertLevel; - + private String alertAdvice; - + private Integer triggerDuration; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/CheckResult.java b/datasophon-common/src/main/java/com/datasophon/common/model/CheckResult.java index c6762f44..905b9374 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/CheckResult.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/CheckResult.java @@ -21,11 +21,11 @@ @Data public class CheckResult { - + private Integer code; - + private String msg; - + public CheckResult(Integer code, String msg) { this.code = code; this.msg = msg; diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ConfigWriter.java b/datasophon-common/src/main/java/com/datasophon/common/model/ConfigWriter.java index e10413c6..c6b203c0 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ConfigWriter.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ConfigWriter.java @@ -23,6 +23,6 @@ @Data public class ConfigWriter { - + private List generators; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/DAG.java b/datasophon-common/src/main/java/com/datasophon/common/model/DAG.java index 2617bfa5..2b6bc0a8 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/DAG.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/DAG.java @@ -14,11 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.common.model; import com.datasophon.common.utils.CollectionUtils; -import java.util.*; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -32,32 +42,32 @@ * EdgeInfo: edge description information */ public class DAG { - + private static final Logger logger = LoggerFactory.getLogger(DAG.class); - + private final ReadWriteLock lock = new ReentrantReadWriteLock(); - + /** * node map, key is node, value is node information */ private volatile Map nodesMap; - + /** * edge map. key is node of origin;value is Map with key for destination node and value for edge */ private volatile Map> edgesMap; - + /** * reversed edge set,key is node of destination, value is Map with key for origin node and value for edge */ private volatile Map> reverseEdgesMap; - + public DAG() { nodesMap = new HashMap<>(); edgesMap = new HashMap<>(); reverseEdgesMap = new HashMap<>(); } - + /** * add node information * @@ -66,15 +76,15 @@ public DAG() { */ public void addNode(Node node, NodeInfo nodeInfo) { lock.writeLock().lock(); - + try { nodesMap.put(node, nodeInfo); } finally { lock.writeLock().unlock(); } - + } - + /** * add edge * @param fromNode node of origin @@ -84,7 +94,7 @@ public void addNode(Node node, NodeInfo nodeInfo) { public boolean addEdge(Node fromNode, Node toNode) { return addEdge(fromNode, toNode, false); } - + /** * add edge * @param fromNode node of origin @@ -95,7 +105,7 @@ public boolean addEdge(Node fromNode, Node toNode) { private boolean addEdge(Node fromNode, Node toNode, boolean createNode) { return addEdge(fromNode, toNode, null, createNode); } - + /** * add edge * @@ -107,28 +117,28 @@ private boolean addEdge(Node fromNode, Node toNode, boolean createNode) { */ public boolean addEdge(Node fromNode, Node toNode, EdgeInfo edge, boolean createNode) { lock.writeLock().lock(); - + try { - + // Whether an edge can be successfully added(fromNode -> toNode) if (!isLegalAddEdge(fromNode, toNode, createNode)) { logger.error("serious error: add edge({} -> {}) is invalid, cause cycle!", fromNode, toNode); return false; } - + addNodeIfAbsent(fromNode, null); addNodeIfAbsent(toNode, null); - + addEdge(fromNode, toNode, edge, edgesMap); addEdge(toNode, fromNode, edge, reverseEdgesMap); - + return true; } finally { lock.writeLock().unlock(); } - + } - + /** * whether this node is contained * @@ -137,14 +147,14 @@ public boolean addEdge(Node fromNode, Node toNode, EdgeInfo edge, boolean create */ public boolean containsNode(Node node) { lock.readLock().lock(); - + try { return nodesMap.containsKey(node); } finally { lock.readLock().unlock(); } } - + /** * whether this edge is contained * @@ -159,13 +169,13 @@ public boolean containsEdge(Node fromNode, Node toNode) { if (endEdges == null) { return false; } - + return endEdges.containsKey(toNode); } finally { lock.readLock().unlock(); } } - + /** * get node description * @@ -174,14 +184,14 @@ public boolean containsEdge(Node fromNode, Node toNode) { */ public NodeInfo getNode(Node node) { lock.readLock().lock(); - + try { return nodesMap.get(node); } finally { lock.readLock().unlock(); } } - + /** * Get the number of nodes * @@ -189,14 +199,14 @@ public NodeInfo getNode(Node node) { */ public int getNodesCount() { lock.readLock().lock(); - + try { return nodesMap.size(); } finally { lock.readLock().unlock(); } } - + /** * Get the number of edges * @@ -206,17 +216,17 @@ public int getEdgesCount() { lock.readLock().lock(); try { int count = 0; - + for (Map.Entry> entry : edgesMap.entrySet()) { count += entry.getValue().size(); } - + return count; } finally { lock.readLock().unlock(); } } - + /** * get the start node of DAG * @@ -224,32 +234,32 @@ public int getEdgesCount() { */ public Collection getBeginNode() { lock.readLock().lock(); - + try { return CollectionUtils.subtract(nodesMap.keySet(), reverseEdgesMap.keySet()); } finally { lock.readLock().unlock(); } - + } - + /** * get the end node of DAG * * @return the end node of DAG */ public Collection getEndNode() { - + lock.readLock().lock(); - + try { return CollectionUtils.subtract(nodesMap.keySet(), edgesMap.keySet()); } finally { lock.readLock().unlock(); } - + } - + /** * Gets all previous nodes of the node * @@ -258,14 +268,14 @@ public Collection getEndNode() { */ public Set getPreviousNodes(Node node) { lock.readLock().lock(); - + try { return getNeighborNodes(node, reverseEdgesMap); } finally { lock.readLock().unlock(); } } - + /** * Get all subsequent nodes of the node * @@ -274,14 +284,14 @@ public Set getPreviousNodes(Node node) { */ public Set getSubsequentNodes(Node node) { lock.readLock().lock(); - + try { return getNeighborNodes(node, edgesMap); } finally { lock.readLock().unlock(); } } - + /** * Gets the degree of entry of the node * @@ -290,14 +300,14 @@ public Set getSubsequentNodes(Node node) { */ public int getIndegree(Node node) { lock.readLock().lock(); - + try { return getPreviousNodes(node).size(); } finally { lock.readLock().unlock(); } } - + /** * whether the graph has a ring * @@ -311,7 +321,7 @@ public boolean hasCycle() { lock.readLock().unlock(); } } - + /** * Only DAG has a topological sort * @return topologically sorted results, returns false if the DAG result is a ring result @@ -319,20 +329,20 @@ public boolean hasCycle() { */ public List topologicalSort() throws Exception { lock.readLock().lock(); - + try { Map.Entry> entry = topologicalSortImpl(); - + if (entry.getKey()) { return entry.getValue(); } - + throw new Exception("serious error: graph has cycle ! "); } finally { lock.readLock().unlock(); } } - + /** * if tho node does not exist,add this node * @@ -344,7 +354,7 @@ private void addNodeIfAbsent(Node node, NodeInfo nodeInfo) { addNode(node, nodeInfo); } } - + /** * add edge * @@ -358,7 +368,7 @@ private void addEdge(Node fromNode, Node toNode, EdgeInfo edge, Map toNodeEdges = edges.get(fromNode); toNodeEdges.put(toNode, edge); } - + /** * Whether an edge can be successfully added(fromNode -> toNode) * need to determine whether the DAG has cycle @@ -373,37 +383,37 @@ private boolean isLegalAddEdge(Node fromNode, Node toNode, boolean createNode) { logger.error("edge fromNode({}) can't equals toNode({})", fromNode, toNode); return false; } - + if (!createNode) { if (!containsNode(fromNode) || !containsNode(toNode)) { logger.error("edge fromNode({}) or toNode({}) is not in vertices map", fromNode, toNode); return false; } } - + // Whether an edge can be successfully added(fromNode -> toNode),need to determine whether the DAG has cycle! int verticesCount = getNodesCount(); - + Queue queue = new LinkedList<>(); - + queue.add(toNode); - + // if DAG doesn't find fromNode, it's not has cycle! while (!queue.isEmpty() && (--verticesCount > 0)) { Node key = queue.poll(); - + for (Node subsequentNode : getSubsequentNodes(key)) { if (subsequentNode.equals(fromNode)) { return false; } - + queue.add(subsequentNode); } } - + return true; } - + /** * Get all neighbor nodes of the node * @@ -413,14 +423,14 @@ private boolean isLegalAddEdge(Node fromNode, Node toNode, boolean createNode) { */ private Set getNeighborNodes(Node node, final Map> edges) { final Map neighborEdges = edges.get(node); - + if (neighborEdges == null) { return Collections.EMPTY_MAP.keySet(); } - + return neighborEdges.keySet(); } - + /** * Determine whether there are ring and topological sorting results * @@ -444,12 +454,12 @@ private Map.Entry> topologicalSortImpl() { List topoResultList = new ArrayList<>(); // save the node whose degree is not 0 Map notZeroIndegreeNodeMap = new HashMap<>(); - + // Scan all the vertices and push vertexs with an entry degree of 0 to queue for (Map.Entry vertices : nodesMap.entrySet()) { Node node = vertices.getKey(); int inDegree = getIndegree(node); - + if (inDegree == 0) { zeroIndegreeNodeQueue.add(node); topoResultList.add(node); @@ -457,7 +467,7 @@ private Map.Entry> topologicalSortImpl() { notZeroIndegreeNodeMap.put(node, inDegree); } } - + /** * After scanning, there is no node with 0 degree of entry, * indicating that there is a ring, and return directly @@ -465,17 +475,17 @@ private Map.Entry> topologicalSortImpl() { if (zeroIndegreeNodeQueue.isEmpty()) { return new AbstractMap.SimpleEntry(false, topoResultList); } - + // The topology algorithm is used to delete nodes with 0 degree of entry and its associated edges while (!zeroIndegreeNodeQueue.isEmpty()) { Node v = zeroIndegreeNodeQueue.poll(); // Get the neighbor node Set subsequentNodes = getSubsequentNodes(v); - + for (Node subsequentNode : subsequentNodes) { - + Integer degree = notZeroIndegreeNodeMap.get(subsequentNode); - + if (--degree == 0) { topoResultList.add(subsequentNode); zeroIndegreeNodeQueue.add(subsequentNode); @@ -483,15 +493,15 @@ private Map.Entry> topologicalSortImpl() { } else { notZeroIndegreeNodeMap.put(subsequentNode, degree); } - + } } - + // if notZeroIndegreeNodeMap is empty,there is no ring! AbstractMap.SimpleEntry resultMap = new AbstractMap.SimpleEntry(notZeroIndegreeNodeMap.size() == 0, topoResultList); return resultMap; - + } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/DAGGraph.java b/datasophon-common/src/main/java/com/datasophon/common/model/DAGGraph.java index 1a7e16b8..fa5d8332 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/DAGGraph.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/DAGGraph.java @@ -19,57 +19,63 @@ import org.apache.commons.collections.CollectionUtils; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Queue; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DAGGraph { - + private static final Logger logger = LoggerFactory.getLogger(DAGGraph.class); - + private Map nodesMap; - + private Map> edgesMap; - + private Map> reverseEdgesMap; - + public DAGGraph() { // 初始化邻接表 nodesMap = new HashMap<>(); edgesMap = new HashMap<>(); reverseEdgesMap = new HashMap<>(); } - + public Map getNodesMap() { return nodesMap; } - + public void setNodesMap(Map nodesMap) { this.nodesMap = nodesMap; } - + public Map> getEdgesMap() { return edgesMap; } - + public void setEdgesMap(Map> edgesMap) { this.edgesMap = edgesMap; } - + public Map> getReverseEdgesMap() { return reverseEdgesMap; } - + public void setReverseEdgesMap(Map> reverseEdgesMap) { this.reverseEdgesMap = reverseEdgesMap; } - + public void addNode(Node node, NodeInfo nodeInfo) { nodesMap.put(node, nodeInfo); } - + public boolean addEdge(Node fromNode, Node toNode, boolean createNode) { // 由于有向图中边是有向的,v->w 边 if (!isLegalAddEdge(fromNode, toNode, createNode)) { @@ -78,30 +84,30 @@ public boolean addEdge(Node fromNode, Node toNode, boolean createNode) { } addNodeIfAbsent(fromNode, null); addNodeIfAbsent(toNode, null); - + addEdge(fromNode, toNode, edgesMap); addEdge(toNode, fromNode, reverseEdgesMap); - + return true; - + } - + private void addEdge(Node fromNode, Node toNode, Map> edges) { edges.putIfAbsent(fromNode, new HashMap<>()); Map toNodeEdges = edges.get(fromNode); toNodeEdges.put(toNode, null); } - + private void addNodeIfAbsent(Node node, NodeInfo nodeInfo) { if (!containsNode(node)) { addNode(node, nodeInfo); } } - + public boolean containsNode(Node node) { return nodesMap.containsKey(node); } - + /** * get the start node of DAG * @@ -110,69 +116,69 @@ public boolean containsNode(Node node) { public Collection getBeginNode() { return CollectionUtils.subtract(nodesMap.keySet(), reverseEdgesMap.keySet()); } - + private boolean isLegalAddEdge(Node fromNode, Node toNode, boolean createNode) { if (fromNode.equals(toNode)) { logger.error("edge fromNode({}) can't equals toNode({})", fromNode, toNode); return false; } - + if (!createNode) { if (!containsNode(fromNode) || !containsNode(toNode)) { logger.error("edge fromNode({}) or toNode({}) is not in vertices map", fromNode, toNode); return false; } } - + // Whether an edge can be successfully added(fromNode -> toNode),need to determine whether the DAG has cycle! int verticesCount = getNodesCount(); - + Queue queue = new LinkedList<>(); - + queue.add(toNode); - + // if DAG doesn't find fromNode, it's not has cycle! while (!queue.isEmpty() && (--verticesCount > 0)) { Node key = queue.poll(); - + for (Node subsequentNode : getSubsequentNodes(key)) { if (subsequentNode.equals(fromNode)) { return false; } - + queue.add(subsequentNode); } } - + return true; } - + public int getNodesCount() { return nodesMap.size(); } - + public Set getSubsequentNodes(Node node) { return getNeighborNodes(node, edgesMap); } - + public Set getPreviousNodes(Node node) { return getNeighborNodes(node, reverseEdgesMap); } - + private Set getNeighborNodes(Node node, final Map> edges) { final Map neighborEdges = edges.get(node); - + if (neighborEdges == null) { return Collections.EMPTY_MAP.keySet(); } - + return neighborEdges.keySet(); } - + public NodeInfo getNode(Node node) { return nodesMap.get(node); } - + public DAGGraph getReverseDagGraph(DAGGraph dagGraph) { DAGGraph reverseDagGraph = new DAGGraph<>(); reverseDagGraph.setNodesMap(dagGraph.getNodesMap()); @@ -180,10 +186,10 @@ public DAGGraph getReverseDagGraph(DAGGraph dag = new DAGGraph<>(); - + Map activeTaskNode = new ConcurrentHashMap<>(); dag.addNode("a", "1"); dag.addNode("b", "2"); @@ -191,11 +197,11 @@ public static void main(String[] args) { dag.addNode("d", "4"); dag.addEdge("a", "b", false); dag.addEdge("a", "c", false); - + Collection beginNode1 = dag.getBeginNode(); for (String node : beginNode1) { activeTaskNode.put(node, ""); - + } for (String node : activeTaskNode.keySet()) { Set subsequentNodes = dag.getSubsequentNodes(node); @@ -206,7 +212,7 @@ public static void main(String[] args) { activeTaskNode.remove(node); } System.out.println(beginNode1); - + } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ExecCmdResult.java b/datasophon-common/src/main/java/com/datasophon/common/model/ExecCmdResult.java index 39e53fcf..cd542714 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ExecCmdResult.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ExecCmdResult.java @@ -23,25 +23,25 @@ * @date: 2022-03-25 21:03 */ public class ExecCmdResult { - + // 命令执行是否成功 private boolean success; - + // 输出结果 private String result; - + public boolean isSuccess() { return success; } - + public void setSuccess(boolean success) { this.success = success; } - + public String getResult() { return result; } - + public void setResult(String result) { this.result = result; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ExternalLink.java b/datasophon-common/src/main/java/com/datasophon/common/model/ExternalLink.java index ab9489e9..73452ff3 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ExternalLink.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ExternalLink.java @@ -23,10 +23,10 @@ @Data public class ExternalLink implements Serializable { - + private String name; - + private String label; - + private String url; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/Generators.java b/datasophon-common/src/main/java/com/datasophon/common/model/Generators.java index ab7ec3f4..5bc57fd0 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/Generators.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/Generators.java @@ -24,15 +24,15 @@ @Data public class Generators implements Serializable { - + private String filename; - + private String configFormat; - + private String outputDirectory; - + private List includeParams; - + private String templateName; @Override public boolean equals(Object o) { @@ -48,10 +48,10 @@ public boolean equals(Object o) { } return false; } - + @Override public int hashCode() { return filename.hashCode(); } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/HostInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/HostInfo.java index aed4a903..d9c9c503 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/HostInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/HostInfo.java @@ -25,43 +25,43 @@ @Data public class HostInfo { - + private String hostname; - + private String ip; /** * 是否受管 */ private boolean managed; - + /** * 检测结果 */ private CheckResult checkResult; - + private String sshUser; - + private Integer sshPort; /** * 安装进度 */ private Integer progress; - + private String clusterCode; - + /** * 安装状态1:正在安装 2:安装成功 3:安装失败 */ private InstallState installState; - + private Integer installStateCode; - + private String errMsg; - + private String message; - + private Date createTime; - + private String cpuArchitecture; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/HostServiceRoleMapping.java b/datasophon-common/src/main/java/com/datasophon/common/model/HostServiceRoleMapping.java index f69e016f..4741666b 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/HostServiceRoleMapping.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/HostServiceRoleMapping.java @@ -20,10 +20,11 @@ import java.util.List; import lombok.Data; + @Data public class HostServiceRoleMapping { - + private String host; - + private List serviceRoles; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ProcInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/ProcInfo.java index 92b4fbd9..2084d77a 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ProcInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ProcInfo.java @@ -21,10 +21,10 @@ @Data public class ProcInfo { - - private String HostName; - - private Boolean Alive; - - private String ErrMsg; + + private String hostName; + + private Boolean alive; + + private String errMsg; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/PromDataInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/PromDataInfo.java index 014eb8a6..6d4a240e 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/PromDataInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/PromDataInfo.java @@ -23,7 +23,7 @@ @Data public class PromDataInfo { - + /** * prometheus结果类型 * vector--瞬时向量 @@ -32,7 +32,7 @@ public class PromDataInfo { * string--字符串 */ private String resultType; - + /** * prometheus指标属性和值 */ diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/PromMetricInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/PromMetricInfo.java index 9995702b..5385342a 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/PromMetricInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/PromMetricInfo.java @@ -19,25 +19,30 @@ import lombok.Data; +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * @Title: prometheus指标属性(这里只反序列化了需要的属性,用户可根据需要做增减) */ @Data public class PromMetricInfo { - + /** * prometheus指标名称 */ - private String __name__; - + @JsonProperty(value = "__name__") + @JSONField(name = "__name__") + private String name; + /** * prometheus实例名称 */ private String instance; - + /** * prometheus任务名称 */ private String job; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/PromResponceInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/PromResponceInfo.java index 841a7bcb..bde21da6 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/PromResponceInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/PromResponceInfo.java @@ -21,11 +21,11 @@ @Data public class PromResponceInfo { - + private String status; /** * prometheus指标属性和值 */ private PromDataInfo data; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/PromResultInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/PromResultInfo.java index 00456ef3..aac2912b 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/PromResultInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/PromResultInfo.java @@ -24,15 +24,15 @@ */ @Data public class PromResultInfo { - + /** * prometheus指标属性 */ private PromMetricInfo metric; - + /** * prometheus指标值 */ private String[] value; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/RunAs.java b/datasophon-common/src/main/java/com/datasophon/common/model/RunAs.java index f4357eaf..29edf7d5 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/RunAs.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/RunAs.java @@ -23,8 +23,8 @@ @Data public class RunAs implements Serializable { - + private String user; - + private String group; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceConfig.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceConfig.java index d746223b..d23665b3 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceConfig.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceConfig.java @@ -24,41 +24,41 @@ @Data public class ServiceConfig implements Serializable { - + private String name; - + private Object value; - + private String label; - + private String description; - + private boolean required; - + private String type; - + private boolean configurableInWizard; - + private Object defaultValue; - + private Integer minValue; - + private Integer maxValue; - + private String unit; - + private boolean hidden; - + private List selectValue; - + private String configType; - + private boolean configWithKerberos; - + private boolean configWithRack; - + private boolean configWithHA; - + private String separator; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceExecuteResultMessage.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceExecuteResultMessage.java index b7686db6..1a8153d4 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceExecuteResultMessage.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceExecuteResultMessage.java @@ -28,21 +28,21 @@ @Data public class ServiceExecuteResultMessage implements Serializable { - + private ServiceExecuteState serviceExecuteState; - + private String serviceName; - + private ServiceRoleType serviceRoleType; - + private Integer clusterId; private String clusterCode; private CommandType commandType; - + private DAGGraph dag; private Map errorTaskList; private Map activeTaskList; private Map readyToSubmitTaskList; private Map completeTaskList; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceInfo.java index 45f10b35..3d9d08f6 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceInfo.java @@ -23,29 +23,29 @@ @Data public class ServiceInfo { - + private String name; - + private String label; - + private String version; - + private String description; - + private List roles; - + private List parameters; - + private List dependencies; - + private ConfigWriter configWriter; - + private String packageName; - + private String decompressPackageName; - + private ExternalLink externalLink; - + private Integer sortNum; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNode.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNode.java index 13640101..a12507f1 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNode.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNode.java @@ -23,13 +23,13 @@ @Data public class ServiceNode { - + private String serviceName; private List masterRoles; private List elseRoles; - + private String commandId; - + private Integer serviceInstanceId; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNodeEdge.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNodeEdge.java index a6c7af30..93d8a7d6 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNodeEdge.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceNodeEdge.java @@ -18,5 +18,5 @@ package com.datasophon.common.model; public class ServiceNodeEdge { - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleHostMapping.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleHostMapping.java index 4d3a94ec..883ba041 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleHostMapping.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleHostMapping.java @@ -23,8 +23,8 @@ @Data public class ServiceRoleHostMapping { - + private String serviceRole; - + private List hosts; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleInfo.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleInfo.java index 9870d22d..73bf6561 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleInfo.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleInfo.java @@ -29,59 +29,59 @@ @Data public class ServiceRoleInfo implements Serializable, Comparable { - + private Integer id; - + private String name; - + private ServiceRoleType roleType; - + private String cardinality; - + private Integer sortNum; - + private ServiceRoleRunner startRunner; - + private ServiceRoleRunner stopRunner; - + private ServiceRoleRunner statusRunner; - + private ExternalLink externalLink; - + private String hostname; - + private String hostCommandId; - + private Integer clusterId; - + private String parentName; - + private String frameCode; - + private String packageName; - + private String decompressPackageName; - + private Map> configFileMap; - + private String logFile; - + private String jmxPort; - + private List> resourceStrategies; - + private boolean isSlave = false; - + private CommandType commandType; - + private String masterHost; - + private Boolean enableRangerPlugin; - + private Integer serviceInstanceId; - + private RunAs runAs; - + @Override public int compareTo(ServiceRoleInfo serviceRoleInfo) { if (Objects.nonNull(serviceRoleInfo.getSortNum()) && Objects.nonNull(this.getSortNum())) { diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleRunner.java b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleRunner.java index 230060f7..7d51271d 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleRunner.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/ServiceRoleRunner.java @@ -24,10 +24,10 @@ @Data public class ServiceRoleRunner implements Serializable { - + private String timeout; - + private String program; - + private List args; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/SimpleServiceConfig.java b/datasophon-common/src/main/java/com/datasophon/common/model/SimpleServiceConfig.java index 9e8e7516..83e7fbbc 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/SimpleServiceConfig.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/SimpleServiceConfig.java @@ -23,9 +23,9 @@ @Data public class SimpleServiceConfig implements Serializable { - + private String name; - + private Object value; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessage.java b/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessage.java index bf05bdf2..0c0fac15 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessage.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessage.java @@ -23,7 +23,7 @@ @Data public class StartWorkerMessage implements Serializable { - + private int coreNum; private double totalMem; private double totalDisk; @@ -36,7 +36,7 @@ public class StartWorkerMessage implements Serializable { private Integer clusterId; private String ip; private String cpuArchitecture; - + private Long deliveryId; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessageConfirmed.java b/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessageConfirmed.java index 73834254..c21f5627 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessageConfirmed.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/StartWorkerMessageConfirmed.java @@ -23,9 +23,9 @@ @Data public class StartWorkerMessageConfirmed implements Serializable { - + private Long deliveryId; - + public StartWorkerMessageConfirmed(Long deliveryId) { this.deliveryId = deliveryId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandHostMessage.java b/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandHostMessage.java index 64cab2dd..0c0606cd 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandHostMessage.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandHostMessage.java @@ -25,14 +25,14 @@ @Data public class UpdateCommandHostMessage implements Serializable { - + private String commandHostId; - + private String hostname; - + private Boolean execResult; - + private ServiceRoleType serviceRoleType; - + private String commandId; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandMessage.java b/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandMessage.java index 790dd8b5..5f17d9ca 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandMessage.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/UpdateCommandMessage.java @@ -23,7 +23,7 @@ @Data public class UpdateCommandMessage implements Serializable { - + private String commandId; - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/model/WorkerServiceMessage.java b/datasophon-common/src/main/java/com/datasophon/common/model/WorkerServiceMessage.java index 04e9406d..828b64ce 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/model/WorkerServiceMessage.java +++ b/datasophon-common/src/main/java/com/datasophon/common/model/WorkerServiceMessage.java @@ -18,10 +18,11 @@ package com.datasophon.common.model; import com.datasophon.common.enums.CommandType; -import lombok.Data; import java.io.Serializable; +import lombok.Data; + /** * 支持 worker 上启动的服务管理 * @@ -29,28 +30,28 @@ */ @Data public class WorkerServiceMessage implements Serializable { - + /** * 节点名称 */ private String hostname; - + /** * Cluster ID */ private Integer clusterId; - + /** * 节点 IP */ private String ip; - + private CommandType commandType; - + public WorkerServiceMessage() { } - - public WorkerServiceMessage(String hostname, Integer clusterId,CommandType commandType) { + + public WorkerServiceMessage(String hostname, Integer clusterId, CommandType commandType) { this.hostname = hostname; this.clusterId = clusterId; this.commandType = commandType; diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/CollectionUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/CollectionUtils.java index 10b895e0..dc813b34 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/CollectionUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/CollectionUtils.java @@ -14,12 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.common.utils; import org.apache.commons.collections.BeanMap; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Provides utility methods and decorators for {@link Collection} instances. @@ -34,10 +42,11 @@ * @since 1.0 */ public class CollectionUtils { - + private CollectionUtils() { throw new IllegalStateException("CollectionUtils class"); } + /** * Returns a new {@link Collection} containing a minus a subset of * b. Only the elements of b that satisfy the predicate @@ -58,20 +67,20 @@ private CollectionUtils() { public static Collection subtract(Set a, Set b) { return CollectionUtils.subtract(a, b); } - + public static boolean isNotEmpty(Collection coll) { return !isEmpty(coll); } - + public static boolean isEmpty(Collection coll) { return coll == null || coll.isEmpty(); } - + /** * The load factor used when none specified in constructor. */ static final float DEFAULT_LOAD_FACTOR = 0.75f; - + /** * String to map * @@ -82,7 +91,7 @@ public static boolean isEmpty(Collection coll) { public static Map stringToMap(String str, String separator) { return stringToMap(str, separator, ""); } - + /** * String to map * @@ -116,24 +125,24 @@ public static Map stringToMap(String str, String separator, Stri } return map; } - + /** * Helper class to easily access cardinality properties of two collections. * * @param the element type */ private static class CardinalityHelper { - + /** * Contains the cardinality for each object in collection A. */ final Map cardinalityA; - + /** * Contains the cardinality for each object in collection B. */ final Map cardinalityB; - + /** * Create a new CardinalityHelper for two collections. * @@ -144,7 +153,7 @@ public CardinalityHelper(final Iterable a, final IterablegetCardinalityMap(a); cardinalityB = CollectionUtils.getCardinalityMap(b); } - + /** * Returns the frequency of this object in collection A. * @@ -154,7 +163,7 @@ public CardinalityHelper(final Iterable a, final Iterable freqMap) { final Integer count = freqMap.get(obj); if (count != null) { @@ -173,7 +182,7 @@ private int getFreq(final Object obj, final Map freqMap) { return 0; } } - + /** * returns {@code true} iff the given {@link Collection}s contain * exactly the same elements with exactly the same cardinalities. @@ -187,14 +196,14 @@ public static boolean equalLists(Collection a, Collection b) { if (a == null && b == null) { return true; } - + if (a == null || b == null) { return false; } - + return isEqualCollection(a, b); } - + /** * Returns {@code true} iff the given {@link Collection}s contain * exactly the same elements with exactly the same cardinalities. @@ -222,7 +231,7 @@ public static boolean isEqualCollection(final Collection a, final Collection< } return true; } - + /** * Returns a {@link Map} mapping each unique element in the given * {@link Collection} to an {@link Integer} representing the number @@ -242,7 +251,7 @@ public static Map getCardinalityMap(final Iterable } return count; } - + /** * Removes certain attributes of each object in the list * @param originList origin list @@ -273,5 +282,5 @@ public static List> getListByExclusion(Li } return instanceList; } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/EncryptionUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/EncryptionUtils.java index bfe3c393..fd5a9910 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/EncryptionUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/EncryptionUtils.java @@ -14,23 +14,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.common.utils; import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; /** * encryption utils */ public class EncryptionUtils { - + /** - * + * * @param rawStr raw string * @return md5(rawStr) */ public static String getMd5(String rawStr) { return DigestUtils.md5Hex(null == rawStr ? StringUtils.EMPTY : rawStr); } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/ExecResult.java b/datasophon-common/src/main/java/com/datasophon/common/utils/ExecResult.java index 2d8adace..1d4bb42e 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/ExecResult.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/ExecResult.java @@ -20,33 +20,33 @@ import java.io.Serializable; public class ExecResult implements Serializable { - + private boolean execResult = false; - + private String execOut; - + private String execErrOut; - + public String getExecErrOut() { return execErrOut; } - + public void setExecErrOut(String execErrOut) { this.execErrOut = execErrOut; } - + public boolean getExecResult() { return execResult; } - + public void setExecResult(boolean execResult) { this.execResult = execResult; } - + public String getExecOut() { return execOut; } - + public void setExecOut(String execOut) { this.execOut = execOut; } diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/FileUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/FileUtils.java index 9ab69164..cdf80f1b 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/FileUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/FileUtils.java @@ -17,8 +17,6 @@ package com.datasophon.common.utils; -import com.google.common.io.CharStreams; -import com.google.common.io.LineProcessor; import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.StringUtils; import org.apache.tools.tar.TarEntry; @@ -33,6 +31,10 @@ import java.nio.charset.Charset; import java.security.MessageDigest; import java.util.zip.GZIPInputStream; + +import com.google.common.io.CharStreams; +import com.google.common.io.LineProcessor; + /** * * 基本文件的特殊操作,文件MD5,从 targz 压缩包不解压读取一个文本文件,读取一个文件的第一行 等 @@ -49,28 +51,26 @@ * @author zhenqin */ public class FileUtils { - - + /** * 获取一个文件的md5值(可处理大文件) * @return md5 value */ public static String md5(File file) { try (FileInputStream fileInputStream = new FileInputStream(file)) { - MessageDigest MD5 = MessageDigest.getInstance("MD5"); - + MessageDigest md5 = MessageDigest.getInstance("MD5"); + byte[] buffer = new byte[8192]; int length; while ((length = fileInputStream.read(buffer)) != -1) { - MD5.update(buffer, 0, length); + md5.update(buffer, 0, length); } - return new String(Hex.encodeHex(MD5.digest())); + return new String(Hex.encodeHex(md5.digest())); } catch (Exception e) { throw new IllegalStateException(e); } } - - + /** * 从 tar.gz 的压缩包内读取一个 文本文件 * @param targz @@ -81,19 +81,20 @@ public static String md5(File file) { public static String readTargzTextFile(File targz, String name, Charset charset) throws IOException { String content = null; TarEntry tarEntry = null; - try (TarInputStream tarInputStream = new TarInputStream(new GZIPInputStream(new FileInputStream(targz))); - BufferedReader reader = new BufferedReader(new InputStreamReader(tarInputStream, charset));){ + try ( + TarInputStream tarInputStream = new TarInputStream(new GZIPInputStream(new FileInputStream(targz))); + BufferedReader reader = new BufferedReader(new InputStreamReader(tarInputStream, charset));) { boolean hasNext = reader.readLine() != null; - if(hasNext) { + if (hasNext) { return null; } - while ((tarEntry = tarInputStream.getNextEntry()) != null ) { + while ((tarEntry = tarInputStream.getNextEntry()) != null) { String entryName = tarEntry.getName(); if (tarEntry.isDirectory()) { // 如果是文件夹,创建文件夹并加速循环 continue; } - if(entryName.endsWith(name)) { + if (entryName.endsWith(name)) { // 找到第一个文件就结束 content = CharStreams.toString(reader); break; @@ -102,8 +103,7 @@ public static String readTargzTextFile(File targz, String name, Charset charset) } return content; } - - + /** * 读取文件第一行,第一行的非空行 * @param file @@ -112,16 +112,16 @@ public static String readTargzTextFile(File targz, String name, Charset charset) */ public static String readFirstLine(File file) throws Exception { final String firstLine = CharStreams.readLines(new FileReader(file), new LineProcessor() { - + String firstLine = null; - + @Override public boolean processLine(String line) throws IOException { this.firstLine = line; // 第一行非空则返回 return StringUtils.trimToNull(line) == null; } - + @Override public String getResult() { return firstLine; @@ -129,7 +129,7 @@ public String getResult() { }); return firstLine; } - + /** * 连接路径 * @param paths diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/HostUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/HostUtils.java index 55932f6d..826018e1 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/HostUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/HostUtils.java @@ -19,7 +19,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.*; +import java.util.Map; import java.util.regex.Pattern; import com.google.common.net.InetAddresses; @@ -31,13 +31,13 @@ */ public enum HostUtils { ; - + public static final Pattern HOST_NAME_STR = Pattern.compile("[0-9a-zA-Z-.]{1,64}"); - + public static boolean checkIP(String ipStr) { return InetAddresses.isInetAddress(ipStr); } - + private static void checkIPThrow(String ipStr, Map ipHost) { if (!checkIP(ipStr)) { throw new RuntimeException("Invalid IP in file /etc/hosts, IP:" + ipStr); @@ -46,26 +46,26 @@ private static void checkIPThrow(String ipStr, Map ipHost) { throw new RuntimeException("Duplicate ip in file /etc/hosts, IP:" + ipStr); } } - + public static boolean checkHostname(String hostname) { if (!HOST_NAME_STR.matcher(hostname).matches()) { return false; } return !hostname.startsWith("-") && !hostname.endsWith("-"); } - + private static void validHostname(String hostname) { if (!checkHostname(hostname)) { throw new RuntimeException("Invalid hostname in file /etc/hosts, hostname:" + hostname); } } - + public static String findIp(String hostname) { validHostname(hostname); String ip = getIp(hostname); return ip; } - + public static String getHostName(String hostOrIp) { try { InetAddress byName = InetAddress.getByName(hostOrIp); @@ -74,7 +74,7 @@ public static String getHostName(String hostOrIp) { throw new RuntimeException(e); } } - + public static String getIp(String hostName) { try { InetAddress byName = InetAddress.getByName(hostName); @@ -83,7 +83,7 @@ public static String getIp(String hostName) { throw new RuntimeException(e); } } - + public static String getLocalIp() { try { InetAddress ip = InetAddress.getLocalHost(); @@ -92,7 +92,7 @@ public static String getLocalIp() { throw new RuntimeException(e); } } - + public static String getLocalHostName() { try { InetAddress ip = InetAddress.getLocalHost(); @@ -101,5 +101,5 @@ public static String getLocalHostName() { throw new RuntimeException(e); } } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/IOUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/IOUtils.java index 8768d903..dafef48c 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/IOUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/IOUtils.java @@ -22,7 +22,7 @@ import java.io.IOException; public class IOUtils { - + public static void closeQuietly(Closeable closeable) { if (closeable != null) { try { diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/OlapUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/OlapUtils.java index fc65f5f3..13b34369 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/OlapUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/OlapUtils.java @@ -18,8 +18,6 @@ package com.datasophon.common.utils; import com.datasophon.common.model.ProcInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.sql.Connection; import java.sql.DriverManager; @@ -30,10 +28,13 @@ import java.util.List; import java.util.Objects; -public class OlapUtils { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +public class OlapUtils { + private static final Logger logger = LoggerFactory.getLogger(OlapUtils.class); - + public static ExecResult addFollower(String feMaster, String hostname) { ExecResult execResult = new ExecResult(); String sql = "ALTER SYSTEM add FOLLOWER \"" + hostname + ":9010\";"; @@ -48,7 +49,7 @@ public static ExecResult addFollower(String feMaster, String hostname) { } return execResult; } - + public static ExecResult addObserver(String feMaster, String hostname) { ExecResult execResult = new ExecResult(); String sql = "ALTER SYSTEM add OBSERVER \"" + hostname + ":9010\";"; @@ -63,12 +64,12 @@ public static ExecResult addObserver(String feMaster, String hostname) { } return execResult; } - + public static ExecResult addBackend(String feMaster, String hostname) { ExecResult execResult = new ExecResult(); String sql = "ALTER SYSTEM add BACKEND \"" + hostname + ":9050\";"; logger.info("Add be to cluster , the sql is {}", sql); - + try { executeSql(feMaster, hostname, sql); execResult.setExecResult(true); @@ -79,7 +80,7 @@ public static ExecResult addBackend(String feMaster, String hostname) { } return execResult; } - + private static void executeSql(String feMaster, String hostname, String sql) throws ClassNotFoundException, SQLException { Connection connection = getConnection(feMaster); @@ -89,7 +90,7 @@ private static void executeSql(String feMaster, String hostname, } close(connection, statement); } - + public static ExecResult addFollowerBySqlClient(String feMaster, String hostname) { String sqlCommand = @@ -102,7 +103,7 @@ public static ExecResult addFollowerBySqlClient(String feMaster, // logger.info("sqlCommand is {}", sqlCommand); return ShellUtils.exceShell(sqlCommand); } - + public static ExecResult addObserverBySqlClient(String feMaster, String hostname) { String sqlCommand = @@ -115,7 +116,7 @@ public static ExecResult addObserverBySqlClient(String feMaster, // logger.info("sqlCommand is {}", sqlCommand); return ShellUtils.exceShell(sqlCommand); } - + public static ExecResult addBackendBySqlClient(String feMaster, String hostname) { String sqlCommand = @@ -128,7 +129,7 @@ public static ExecResult addBackendBySqlClient(String feMaster, // logger.info("sqlCommand is {}", sqlCommand); return ShellUtils.exceShell(sqlCommand); } - + private static Connection getConnection(String feMaster) throws ClassNotFoundException, SQLException { String username = "root"; String password = ""; @@ -137,38 +138,38 @@ private static Connection getConnection(String feMaster) throws ClassNotFoundExc Class.forName("com.mysql.cj.jdbc.Driver"); return DriverManager.getConnection(url, username, password); } - + private static void close(Connection connection, Statement statement) throws SQLException { if (Objects.nonNull(connection) && Objects.nonNull(statement)) { statement.close(); connection.close(); } } - + public static List showFrontends(String feMaster) throws SQLException, ClassNotFoundException { String sql = "SHOW PROC '/frontends';"; // logger.info("sql is {}", sql); return executeQueryProcInfo(feMaster, sql); } - + public static List listDeadFrontends(String feMaster) throws SQLException, ClassNotFoundException { String sql = "SHOW PROC '/frontends';"; // logger.info("sql is {}", sql); return getDeadProcInfos(feMaster, sql); } - + public static List listDeadBackends(String feMaster) throws SQLException, ClassNotFoundException { String sql = "SHOW PROC '/frontends';"; // logger.info("sql is {}",sql); return getDeadProcInfos(feMaster, sql); } - + public static List showBackends(String feMaster) throws SQLException, ClassNotFoundException { String sql = "SHOW PROC '/backends';"; // logger.info("sql is {}",sql); return executeQueryProcInfo(feMaster, sql); } - + public static List executeQueryProcInfo(String feMaster, String sql) throws SQLException, ClassNotFoundException { Connection connection = getConnection(feMaster); @@ -187,7 +188,7 @@ public static List executeQueryProcInfo(String feMaster, close(connection, statement); return list; } - + public static List executeQuerySql(String feMaster, String sql) throws SQLException, ClassNotFoundException { Connection connection = getConnection(feMaster); @@ -205,7 +206,7 @@ public static List executeQuerySql(String feMaster, close(connection, statement); return list; } - + private static List getDeadProcInfos(String feMaster, String sql) throws SQLException, ClassNotFoundException { List list = executeQueryProcInfo(feMaster, sql); diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/PlaceholderUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/PlaceholderUtils.java index 90708d96..e229a732 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/PlaceholderUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/PlaceholderUtils.java @@ -28,9 +28,9 @@ import org.slf4j.LoggerFactory; public class PlaceholderUtils { - + private static final Logger logger = LoggerFactory.getLogger(PlaceholderUtils.class); - + public static void main(String[] args) { HashMap paramMap = new HashMap<>(); paramMap.put("${apiHost}", "ddp1016"); @@ -62,17 +62,17 @@ public static void main(String[] args) { " \"defaultValue\": \"${apiPort}\"\n" + " }\n" + " ]", paramMap, regex); - + System.out.println(replacePlaceholders); List newEquipmentNoList = PlaceholderUtils.getNewEquipmentNoList("001", "002"); for (String s : newEquipmentNoList) { System.out.println(s); } } - + public static String replacePlaceholders(String value, Map paramsMap, String regex) { - + Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(value); // 自旋进行最小匹配,直到无法匹配 @@ -86,11 +86,11 @@ public static String replacePlaceholders(String value, } return value; } - + public static List getMatchValue(String value) { String regex = "\\[.*?\\]"; ArrayList list = new ArrayList<>(); - + Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(value); // 自旋进行最小匹配,直到无法匹配 @@ -101,7 +101,7 @@ public static List getMatchValue(String value) { } return list; } - + public static List getNewEquipmentNoList(String pre, String last) { int length = pre.length(); ArrayList list = new ArrayList<>(); @@ -116,5 +116,5 @@ public static List getNewEquipmentNoList(String pre, String last) { } return list; } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/PromInfoUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/PromInfoUtils.java index 631b7f64..71d62579 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/PromInfoUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/PromInfoUtils.java @@ -22,7 +22,7 @@ import com.datasophon.common.model.PromResponceInfo; import com.datasophon.common.model.PromResultInfo; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.List; @@ -41,11 +41,11 @@ * @Description: */ public class PromInfoUtils { - + private static final Logger log = LoggerFactory.getLogger(PromInfoUtils.class); - + public static List getPrometheusMetrics(String promURL, String promQL) { - + // log.info("请求地址:{},请求QL:{}", promURL, promQL); Map param = new HashMap(); param.put(Constants.QUERY, promQL); @@ -68,9 +68,9 @@ public static List getPrometheusMetrics(String promURL, String p List result = responceInfo.getData().getResult(); return result; } - + public static String getSinglePrometheusMetric(String promURL, String promQL) { - + // log.info("请求地址:{},请求QL:{}", promURL, promQL); Map param = new HashMap(); param.put(Constants.QUERY, promQL); @@ -97,17 +97,17 @@ public static String getSinglePrometheusMetric(String promURL, String promQL) { } return null; } - + public static void main(String[] args) { // List windowsOsInfo = getWindowsInfo("http://10.0.50.225:9090/api/v1/query", // PromConstants.WINDOWS_OS_INFO); - + List hadoop_nameNode_threads = getPrometheusMetrics("http://172.31.96.16:9090/api/v1/query", "up{job=\"hdfs\",instance=\"172.31.96.16:27001\"}"); for (PromResultInfo hadoop_nameNode_thread : hadoop_nameNode_threads) { PromMetricInfo metric = hadoop_nameNode_thread.getMetric(); - log.info(metric.get__name__() + ":" + hadoop_nameNode_thread.getValue()[1]); + log.info(metric.getName() + ":" + hadoop_nameNode_thread.getValue()[1]); } } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/PropertyUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/PropertyUtils.java index 7d32d073..450263dd 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/PropertyUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/PropertyUtils.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.common.utils; import java.io.IOException; @@ -30,20 +31,20 @@ * single instance */ public class PropertyUtils { - + /** * logger */ private static final Logger logger = LoggerFactory.getLogger(PropertyUtils.class); - + private static final Properties properties = new Properties(); - + private PropertyUtils() { throw new UnsupportedOperationException("Construct PropertyUtils"); } - + private static final String COMMON_PROPERTIES_PATH = "/common.properties"; - + static { String[] propertyFiles = new String[]{COMMON_PROPERTIES_PATH}; for (String fileName : propertyFiles) { @@ -51,7 +52,7 @@ private PropertyUtils() { try { fis = PropertyUtils.class.getResourceAsStream(fileName); properties.load(fis); - + } catch (IOException e) { logger.error(e.getMessage(), e); if (fis != null) { @@ -63,7 +64,7 @@ private PropertyUtils() { } } } - + /** * get property value * @@ -73,7 +74,7 @@ private PropertyUtils() { public static String getString(String key) { return properties.getProperty(key.trim()); } - + /** * get property value with upper case * @@ -83,7 +84,7 @@ public static String getString(String key) { public static String getUpperCaseString(String key) { return properties.getProperty(key.trim()).toUpperCase(); } - + /** * get property value * @@ -95,7 +96,7 @@ public static String getString(String key, String defaultVal) { String val = properties.getProperty(key.trim()); return val == null ? defaultVal : val; } - + /** * get property value * @@ -105,7 +106,7 @@ public static String getString(String key, String defaultVal) { public static int getInt(String key) { return getInt(key, -1); } - + /** * * @param key key @@ -117,7 +118,7 @@ public static int getInt(String key, int defaultValue) { if (value == null) { return defaultValue; } - + try { return Integer.parseInt(value); } catch (NumberFormatException e) { @@ -125,7 +126,7 @@ public static int getInt(String key, int defaultValue) { } return defaultValue; } - + /** * get property value * @@ -137,10 +138,10 @@ public static boolean getBoolean(String key) { if (null != value) { return Boolean.parseBoolean(value); } - + return false; } - + /** * get property value * @@ -153,10 +154,10 @@ public static Boolean getBoolean(String key, boolean defaultValue) { if (null != value) { return Boolean.parseBoolean(value); } - + return defaultValue; } - + /** * get property long value * @param key key @@ -167,7 +168,7 @@ public static long getLong(String key, long defaultVal) { String val = getString(key); return val == null ? defaultVal : Long.parseLong(val); } - + /** * * @param key key @@ -176,7 +177,7 @@ public static long getLong(String key, long defaultVal) { public static long getLong(String key) { return getLong(key, -1); } - + /** * * @param key key @@ -187,7 +188,7 @@ public double getDouble(String key, double defaultVal) { String val = getString(key); return val == null ? defaultVal : Double.parseDouble(val); } - + /** * get array * @param key property name @@ -207,7 +208,7 @@ public static String[] getArray(String key, String splitStr) { } return new String[0]; } - + /** * * @param key key @@ -221,7 +222,7 @@ public > T getEnum(String key, Class type, String val = getString(key); return val == null ? defaultValue : Enum.valueOf(type, val); } - + /** * get all properties with specified prefix, like: fs. * @param prefix prefix to search @@ -236,12 +237,12 @@ public static Map getPrefixedProperties(String prefix) { } return matchedProperties; } - + /** * */ public static void setValue(String key, String value) { properties.setProperty(key, value); } - + } diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/Result.java b/datasophon-common/src/main/java/com/datasophon/common/utils/Result.java index cf71d91c..792872c6 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/Result.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/Result.java @@ -28,50 +28,50 @@ @Data public class Result extends HashMap { - + private static final long serialVersionUID = 1L; - + private Integer code; private String msg; - + private Object data; - + public Result() { } - + public static Result error() { return error(500, "未知异常,请联系管理员"); } - + public static Result error(String msg) { return error(500, msg); } - + public static Result error(int code, String msg) { Result result = new Result(); result.put("code", code); result.put("msg", msg); return result; } - + public static Result success(Map map) { Result result = new Result(); result.putAll(map); return result; } - + public Integer getCode() { return (Integer) this.get(Constants.CODE); } - + public Object getData() { return this.get(Constants.DATA); } - + public boolean isSuccess() { return this.getCode() == 200; } - + public static Result success(Object data) { Result result = new Result(); result.put(Constants.CODE, 200); @@ -79,19 +79,20 @@ public static Result success(Object data) { result.put("data", data); return result; } + public static Result success() { Result result = new Result(); result.put(Constants.CODE, 200); result.put(Constants.MSG, "success"); return result; } - + public static Result successEmptyCount() { Result result = success(new ArrayList<>(0)); result.put(Constants.TOTAL, 0); return result; } - + @Override public Result put(String key, Object value) { super.put(key, value); diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/ShellUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/ShellUtils.java index 9f1c4489..187d68c4 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/ShellUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/ShellUtils.java @@ -18,9 +18,6 @@ package com.datasophon.common.utils; import com.datasophon.common.Constants; -import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -34,12 +31,15 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -public class ShellUtils { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +public class ShellUtils { + private static ProcessBuilder processBuilder = new ProcessBuilder(); - + private static final Logger logger = LoggerFactory.getLogger(ShellUtils.class); - + public static Process exec(List command) { Process process = null; try { @@ -52,7 +52,7 @@ public static Process exec(List command) { } return process; } - + /** * @param pathOrCommand 脚本路径或者命令 * @return @@ -83,14 +83,14 @@ public static ExecResult exceShell(String pathOrCommand) { result.setExecOut("call shell failed. error code is :" + exitValue); logger.error("{} command exec out is : {} {}", pathOrCommand, System.lineSeparator(), execOut); } - + } catch (Exception e) { result.setExecOut(e.getMessage()); logger.error(e.getMessage(), e); } return result; } - + // 获取cpu架构 arm或x86 public static String getCpuArchitecture() { try { @@ -115,8 +115,7 @@ public static String getCpuArchitecture() { } return null; } - - + public static ExecResult execWithStatus(String workPath, List command, long timeout) { Process process = null; ExecResult result = new ExecResult(); @@ -141,7 +140,7 @@ public static ExecResult execWithStatus(String workPath, List command, l } return result; } - + public static ExecResult execWithStatus(String workPath, List command, long timeout, Logger logger) { Process process = null; ExecResult result = new ExecResult(); @@ -166,11 +165,11 @@ public static ExecResult execWithStatus(String workPath, List command, l } return result; } - + public static void getOutput(Process process, Logger logger) { - + ExecutorService getOutputLogService = Executors.newSingleThreadExecutor(); - + getOutputLogService.submit(() -> { BufferedReader inReader = null; try { @@ -205,11 +204,11 @@ public static void getOutput(Process process, Logger logger) { }); getOutputLogService.shutdown(); } - + public static void getOutput(Process process) { - + ExecutorService getOutputLogService = Executors.newSingleThreadExecutor(); - + getOutputLogService.submit(() -> { BufferedReader inReader = null; try { @@ -229,7 +228,7 @@ public static void getOutput(Process process) { }); getOutputLogService.shutdown(); } - + public static String getError(Process process) { String errput = null; BufferedReader reader = null; @@ -248,7 +247,7 @@ public static String getError(Process process) { closeQuietly(reader); return errput; } - + public static void closeQuietly(Reader reader) { try { if (reader != null) { @@ -258,13 +257,13 @@ public static void closeQuietly(Reader reader) { logger.error(ioe.getMessage(), ioe); } } - + public static void destroy(Process process) { if (process != null) { process.destroyForcibly(); } } - + public static void addChmod(String path, String chmod) { ArrayList command = new ArrayList<>(); command.add("chmod"); @@ -273,7 +272,7 @@ public static void addChmod(String path, String chmod) { command.add(path); execWithStatus(Constants.INSTALL_PATH, command, 60, logger); } - + public static void addChown(String path, String user, String group) { ArrayList command = new ArrayList<>(); command.add("chown"); diff --git a/datasophon-common/src/main/java/com/datasophon/common/utils/ThrowableUtils.java b/datasophon-common/src/main/java/com/datasophon/common/utils/ThrowableUtils.java index 7d1b2f50..d4a6f5ac 100644 --- a/datasophon-common/src/main/java/com/datasophon/common/utils/ThrowableUtils.java +++ b/datasophon-common/src/main/java/com/datasophon/common/utils/ThrowableUtils.java @@ -21,7 +21,7 @@ import java.io.StringWriter; public class ThrowableUtils { - + public static String getStackTrace(Throwable throwable) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); diff --git a/datasophon-domain/pom.xml b/datasophon-domain/pom.xml index 05ca7217..f5d6864b 100644 --- a/datasophon-domain/pom.xml +++ b/datasophon-domain/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 - datasophon com.datasophon + datasophon ${revision} - 4.0.0 datasophon-domain @@ -31,8 +30,8 @@ log4j-to-slf4j - spring-boot-starter-logging org.springframework.boot + spring-boot-starter-logging @@ -89,4 +88,4 @@ - \ No newline at end of file + diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/alert/gateway/AlertHistoryGateway.java b/datasophon-domain/src/main/java/com/datasophon/domain/alert/gateway/AlertHistoryGateway.java index 606592ea..347faaca 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/alert/gateway/AlertHistoryGateway.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/alert/gateway/AlertHistoryGateway.java @@ -3,11 +3,12 @@ import com.datasophon.domain.alert.model.AlertHistory; public interface AlertHistoryGateway { + boolean hasEnabledAlertHistory(String alertname, int clusterId, String hostname); - + AlertHistory getEnabledAlertHistory(String alertname, int clusterId, String hostname); - + void updateAlertHistoryToDisabled(Integer id); - + boolean nodeHasWarnAlertList(String hostname, String serviceRoleName, Integer id); } diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertHistory.java b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertHistory.java index 715eaa0b..20ef0b61 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertHistory.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertHistory.java @@ -1,10 +1,12 @@ package com.datasophon.domain.alert.model; +import java.util.Date; + import lombok.Data; -import java.util.Date; @Data public class AlertHistory { + /** * 主键 */ diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertLabels.java b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertLabels.java index e9f9200f..3b866bd7 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertLabels.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertLabels.java @@ -22,12 +22,12 @@ @Data public class AlertLabels { - + private String alertname; private int clusterId; private String serviceRoleName; private String instance; private String job; private String severity; - + } diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertMessage.java b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertMessage.java index 16e63e76..18b4c5ae 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertMessage.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/AlertMessage.java @@ -18,13 +18,13 @@ package com.datasophon.domain.alert.model; -import lombok.Data; - import java.util.List; +import lombok.Data; + @Data public class AlertMessage { - + private String receiver; private String status; private List alerts; @@ -32,5 +32,5 @@ public class AlertMessage { private String version; private String groupKey; private int truncatedAlerts; - + } diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Alerts.java b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Alerts.java index b25164a8..1b685b59 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Alerts.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Alerts.java @@ -22,7 +22,7 @@ @Data public class Alerts { - + private String status; private AlertLabels labels; private String startsAt; diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Annotations.java b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Annotations.java index dd90cfe6..26cb7e9f 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Annotations.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/alert/model/Annotations.java @@ -22,8 +22,8 @@ @Data public class Annotations { - + private String description; private String summary; - + } diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/HostState.java b/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/HostState.java index 3a947e9d..1f0e1339 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/HostState.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/HostState.java @@ -21,38 +21,38 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum HostState { - + RUNNING(1, "正在运行"), OFFLINE(2, "掉线"), EXISTS_ALARM(3, "存在告警"); - + @EnumValue private int value; - + private String desc; - + HostState(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/MANAGED.java b/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/MANAGED.java index 282be4a5..78e7a1f4 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/MANAGED.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/host/enums/MANAGED.java @@ -20,34 +20,34 @@ import com.baomidou.mybatisplus.annotation.EnumValue; public enum MANAGED { - + YES(1, true), NO(2, false); - + @EnumValue private int value; - + private boolean desc; - + MANAGED(int value, boolean desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + public boolean isDesc() { return desc; } - + public void setDesc(boolean desc) { this.desc = desc; } - + } diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/host/model/DynamicHostProp.java b/datasophon-domain/src/main/java/com/datasophon/domain/host/model/DynamicHostProp.java index b273275e..914de4f6 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/host/model/DynamicHostProp.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/host/model/DynamicHostProp.java @@ -1,13 +1,15 @@ package com.datasophon.domain.host.model; import com.datasophon.domain.host.enums.HostState; -import lombok.Data; import java.util.Date; import java.util.List; +import lombok.Data; + @Data public class DynamicHostProp { + /** * 已用内存 */ @@ -32,6 +34,6 @@ public class DynamicHostProp { * 1:受管 2:断线 */ private Integer managed; - + private List serviceRoles; } diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/host/model/Host.java b/datasophon-domain/src/main/java/com/datasophon/domain/host/model/Host.java index ba74c30b..76bd96f3 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/host/model/Host.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/host/model/Host.java @@ -1,12 +1,12 @@ package com.datasophon.domain.host.model; -import lombok.Data; - import java.util.Date; +import lombok.Data; + @Data public class Host { - + /** * 主机名 */ @@ -31,20 +31,20 @@ public class Host { * 总磁盘 */ private Integer totalDisk; - + private DynamicHostProp dynamicHostProp; /** * 集群id */ private Integer clusterId; - + private String cpuArchitecture; - + private String nodeLabel; - + /** * 创建时间 */ private Date createTime; - + } diff --git a/datasophon-domain/src/main/java/com/datasophon/domain/host/model/ServiceRole.java b/datasophon-domain/src/main/java/com/datasophon/domain/host/model/ServiceRole.java index 3eada891..f83ed342 100644 --- a/datasophon-domain/src/main/java/com/datasophon/domain/host/model/ServiceRole.java +++ b/datasophon-domain/src/main/java/com/datasophon/domain/host/model/ServiceRole.java @@ -4,7 +4,7 @@ @Data public class ServiceRole { - + private String serviceRoleName; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/alert/AlertHistoryGatewayImpl.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/alert/AlertHistoryGatewayImpl.java index fec0855e..3a664e18 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/alert/AlertHistoryGatewayImpl.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/alert/AlertHistoryGatewayImpl.java @@ -1,25 +1,27 @@ package com.datasophon.dao.alert; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.datasophon.dao.entity.ClusterAlertHistory; import com.datasophon.dao.enums.AlertLevel; import com.datasophon.dao.mapper.ClusterAlertHistoryMapper; import com.datasophon.domain.alert.gateway.AlertHistoryGateway; import com.datasophon.domain.alert.model.AlertHistory; + +import java.util.List; +import java.util.Objects; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.util.List; -import java.util.Objects; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @Component public class AlertHistoryGatewayImpl implements AlertHistoryGateway { - + @Autowired private ClusterAlertHistoryMapper alertHistoryMapper; - + @Override public boolean hasEnabledAlertHistory(String alertname, int clusterId, String hostname) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -33,7 +35,7 @@ public boolean hasEnabledAlertHistory(String alertname, int clusterId, String ho } return false; } - + @Override public AlertHistory getEnabledAlertHistory(String alertname, int clusterId, String hostname) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -42,22 +44,22 @@ public AlertHistory getEnabledAlertHistory(String alertname, int clusterId, Stri .eq(ClusterAlertHistory::getHostname, hostname) .eq(ClusterAlertHistory::getIsEnabled, 1); ClusterAlertHistory clusterAlertHistory = alertHistoryMapper.selectOne(queryWrapper); - if(Objects.nonNull(clusterAlertHistory)){ + if (Objects.nonNull(clusterAlertHistory)) { AlertHistory alertHistory = new AlertHistory(); - BeanUtils.copyProperties(clusterAlertHistory,alertHistory); + BeanUtils.copyProperties(clusterAlertHistory, alertHistory); alertHistory.setAlertLevel(clusterAlertHistory.getAlertLevel().getValue()); return alertHistory; } return null; } - + @Override public void updateAlertHistoryToDisabled(Integer id) { ClusterAlertHistory clusterAlertHistory = alertHistoryMapper.selectById(id); clusterAlertHistory.setIsEnabled(2); alertHistoryMapper.updateById(clusterAlertHistory); } - + @Override public boolean nodeHasWarnAlertList(String hostname, String serviceRoleName, Integer id) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -67,7 +69,7 @@ public boolean nodeHasWarnAlertList(String hostname, String serviceRoleName, Int .eq(ClusterAlertHistory::getAlertLevel, AlertLevel.WARN) .ne(ClusterAlertHistory::getId, id); List clusterAlertHistories = alertHistoryMapper.selectList(queryWrapper); - if(CollectionUtils.isEmpty(clusterAlertHistories)){ + if (CollectionUtils.isEmpty(clusterAlertHistories)) { return false; } return true; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/AlertGroupEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/AlertGroupEntity.java index 37694d0a..15c79187 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/AlertGroupEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/AlertGroupEntity.java @@ -29,9 +29,9 @@ @TableName("t_ddh_alert_group") @Data public class AlertGroupEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -45,13 +45,13 @@ public class AlertGroupEntity implements Serializable { * 告警组类别 */ private String alertGroupCategory; - + private Date createTime; - + @TableField(exist = false) private Integer alertQuotaNum; - + @TableField(exist = false) private Integer clusterId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertExpression.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertExpression.java index 5a795aeb..f2c114d6 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertExpression.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertExpression.java @@ -28,9 +28,9 @@ @Data @TableName("t_ddh_cluster_alert_expression") public class ClusterAlertExpression implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 自增 ID */ @@ -72,5 +72,5 @@ public class ClusterAlertExpression implements Serializable { * 修改时间 */ private Date updateTime; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertGroupMap.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertGroupMap.java index 9d56b5a2..f263feff 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertGroupMap.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertGroupMap.java @@ -27,9 +27,9 @@ @Data @TableName("t_ddh_cluster_alert_group_map") public class ClusterAlertGroupMap implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -43,5 +43,5 @@ public class ClusterAlertGroupMap implements Serializable { * */ private Integer alertGroupId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertHistory.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertHistory.java index 0c94a306..27485e2c 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertHistory.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertHistory.java @@ -17,16 +17,18 @@ package com.datasophon.dao.entity; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; import com.datasophon.dao.enums.AlertLevel; + +import java.io.Serializable; +import java.util.Date; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.io.Serializable; -import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; @Data @Builder @@ -34,9 +36,9 @@ @NoArgsConstructor @AllArgsConstructor public class ClusterAlertHistory implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -90,5 +92,5 @@ public class ClusterAlertHistory implements Serializable { * 集群id */ private Integer clusterId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertQuota.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertQuota.java index b86e7491..8398fd9f 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertQuota.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertQuota.java @@ -32,9 +32,9 @@ @Data @TableName("t_ddh_cluster_alert_quota") public class ClusterAlertQuota implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -88,17 +88,17 @@ public class ClusterAlertQuota implements Serializable { * 触发时长 单位秒 */ private Integer triggerDuration; - + private String serviceRoleName; - + private QuotaState quotaState; - + private Date createTime; - + @TableField(exist = false) private Integer quotaStateCode; - + @TableField(exist = false) private String alertGroupName; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertRule.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertRule.java index 54d7de23..05b9a338 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertRule.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterAlertRule.java @@ -28,9 +28,9 @@ @Data @TableName("t_ddh_cluster_alert_rule") public class ClusterAlertRule implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 自增 ID */ @@ -96,5 +96,5 @@ public class ClusterAlertRule implements Serializable { * 集群id */ private Integer clusterId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterGroup.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterGroup.java index 4a6c04fa..4ce76616 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterGroup.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterGroup.java @@ -28,17 +28,17 @@ @Data @TableName("t_ddh_cluster_group") public class ClusterGroup implements Serializable { - + private static final long serialVersionUID = 1L; - + @TableId private Integer id; - + private String groupName; - + private Integer clusterId; - + @TableField(exist = false) private String clusterUsers; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterHostDO.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterHostDO.java index bb8379be..1581c1b1 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterHostDO.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterHostDO.java @@ -17,22 +17,24 @@ package com.datasophon.dao.entity; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; import com.datasophon.domain.host.enums.HostState; import com.datasophon.domain.host.enums.MANAGED; -import lombok.Data; import java.io.Serializable; import java.util.Date; +import lombok.Data; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + @TableName("t_ddh_cluster_host") @Data public class ClusterHostDO implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -94,12 +96,12 @@ public class ClusterHostDO implements Serializable { * 1:受管 2:断线 */ private MANAGED managed; - + private String cpuArchitecture; - + private String nodeLabel; - + @TableField(exist = false) private Integer serviceRoleNum; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterInfoEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterInfoEntity.java index 69794d40..8d95271c 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterInfoEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterInfoEntity.java @@ -32,9 +32,9 @@ @Data @TableName("t_ddh_cluster_info") public class ClusterInfoEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -72,11 +72,11 @@ public class ClusterInfoEntity implements Serializable { * 集群框架id */ private Integer frameId; - + @TableField(exist = false) private List clusterManagerList; - + @TableField(exist = false) private Integer clusterStateCode; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterNodeLabelEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterNodeLabelEntity.java index 49179ac1..51147aa5 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterNodeLabelEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterNodeLabelEntity.java @@ -25,11 +25,11 @@ @Data @TableName("t_ddh_cluster_node_label") public class ClusterNodeLabelEntity { - + @TableId private Integer id; - + private Integer clusterId; - + private String nodeLabel; } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterQueueCapacity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterQueueCapacity.java index c9a6f12b..be6ca8aa 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterQueueCapacity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterQueueCapacity.java @@ -27,15 +27,15 @@ @Data @TableName("t_ddh_cluster_queue_capacity") public class ClusterQueueCapacity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @TableId private Integer id; - + private Integer clusterId; /** * @@ -53,7 +53,7 @@ public class ClusterQueueCapacity implements Serializable { * */ private String aclUsers; - + private String parent; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRack.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRack.java index 6e91eec2..476a261e 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRack.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRack.java @@ -27,9 +27,9 @@ @Data @TableName("t_ddh_cluster_rack") public class ClusterRack implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -43,5 +43,5 @@ public class ClusterRack implements Serializable { * */ private Integer clusterId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRoleUserEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRoleUserEntity.java index a4429561..f9bbaeb9 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRoleUserEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterRoleUserEntity.java @@ -29,9 +29,9 @@ @Data @TableName("t_ddh_cluster_role_user") public class ClusterRoleUserEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -49,5 +49,5 @@ public class ClusterRoleUserEntity implements Serializable { * 用户id */ private Integer userId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandEntity.java index effff357..342473fa 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandEntity.java @@ -30,9 +30,9 @@ @TableName("t_ddh_cluster_service_command") @Data public class ClusterServiceCommandEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -53,7 +53,7 @@ public class ClusterServiceCommandEntity implements Serializable { * 命令状态 1:正在运行2:成功3:失败 */ private CommandState commandState; - + @TableField(exist = false) private Integer commandStateCode; /** @@ -72,12 +72,12 @@ public class ClusterServiceCommandEntity implements Serializable { * 命令类型 */ private Integer commandType; - + @TableField(exist = false) private String durationTime; - + private Date endTime; - + private Integer serviceInstanceId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostCommandEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostCommandEntity.java index ae7c3183..2f436a4b 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostCommandEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostCommandEntity.java @@ -31,9 +31,9 @@ @TableName("t_ddh_cluster_service_command_host_command") @Data public class ClusterServiceCommandHostCommandEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -46,7 +46,7 @@ public class ClusterServiceCommandHostCommandEntity implements Serializable { * 指令状态 1、正在运行2:成功3:失败 */ private CommandState commandState; - + @TableField(exist = false) private Integer commandStateCode; /** @@ -57,21 +57,21 @@ public class ClusterServiceCommandHostCommandEntity implements Serializable { * 主机id */ private String commandHostId; - + private String commandId; - + private String hostname; /** * 服务角色名称 */ private String serviceRoleName; - + private RoleType serviceRoleType; - + private String resultMsg; - + private Date createTime; - + private Integer commandType; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostEntity.java index 8d58d2cb..930177d0 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceCommandHostEntity.java @@ -30,9 +30,9 @@ @TableName("t_ddh_cluster_service_command_host") @Data public class ClusterServiceCommandHostEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -45,7 +45,7 @@ public class ClusterServiceCommandHostEntity implements Serializable { * 命令状态 1:正在运行2:成功3:失败 */ private CommandState commandState; - + @TableField(exist = false) private Integer commandStateCode; /** @@ -56,7 +56,7 @@ public class ClusterServiceCommandHostEntity implements Serializable { * 操作指令id */ private String commandId; - + private Date createTime; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceDashboard.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceDashboard.java index 262a3861..351d4d54 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceDashboard.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceDashboard.java @@ -27,9 +27,9 @@ @Data @TableName("t_ddh_cluster_service_dashboard") public class ClusterServiceDashboard implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主机 */ @@ -43,5 +43,5 @@ public class ClusterServiceDashboard implements Serializable { * 总览页面地址 */ private String dashboardUrl; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceConfigEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceConfigEntity.java index eaf0fae7..ef873137 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceConfigEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceConfigEntity.java @@ -28,9 +28,9 @@ @TableName("t_ddh_cluster_service_instance_config") @Data public class ClusterServiceInstanceConfigEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主机 */ @@ -64,9 +64,9 @@ public class ClusterServiceInstanceConfigEntity implements Serializable { * */ private Integer clusterId; - + private String configFileJson; - + private String configFileJsonMd5; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceEntity.java index cc461443..6668fa16 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceEntity.java @@ -32,9 +32,9 @@ @TableName("t_ddh_cluster_service_instance") @Data public class ClusterServiceInstanceEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -48,13 +48,13 @@ public class ClusterServiceInstanceEntity implements Serializable { * 服务名称 */ private String serviceName; - + private String label; /** * 服务状态 1、待安装 2:正在运行 3:存在告警 4:存在异常 */ private ServiceState serviceState; - + @TableField(exist = false) private Integer serviceStateCode; /** @@ -65,16 +65,16 @@ public class ClusterServiceInstanceEntity implements Serializable { * 创建时间 */ private Date createTime; - + private NeedRestart needRestart; - + private Integer frameServiceId; - + @TableField(exist = false) private String dashboardUrl; - + @TableField(exist = false) private Integer alertNum; - + private Integer sortNum; } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceRoleGroup.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceRoleGroup.java index f0afc6cc..8fc91cdd 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceRoleGroup.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceInstanceRoleGroup.java @@ -31,9 +31,9 @@ @Data @TableName("t_ddh_cluster_service_instance_role_group") public class ClusterServiceInstanceRoleGroup implements Serializable { - + private static final long serialVersionUID = 1L; - + /** */ @TableId private Integer id; @@ -45,8 +45,8 @@ public class ClusterServiceInstanceRoleGroup implements Serializable { private String serviceName; /** */ private Integer clusterId; - + private String roleGroupType; - + private NeedRestart needRestart; } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleGroupConfig.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleGroupConfig.java index cd4f9c21..5b820e83 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleGroupConfig.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleGroupConfig.java @@ -28,9 +28,9 @@ @Data @TableName("t_ddh_cluster_service_role_group_config") public class ClusterServiceRoleGroupConfig implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -76,5 +76,5 @@ public class ClusterServiceRoleGroupConfig implements Serializable { * */ private String serviceName; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceConfigEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceConfigEntity.java index 84f46f84..4e90e78c 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceConfigEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceConfigEntity.java @@ -22,15 +22,16 @@ import lombok.Data; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @Data @TableName("t_ddh_cluster_service_role_instance_config") public class ClusterServiceRoleInstanceConfigEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主机 */ @@ -39,26 +40,36 @@ public class ClusterServiceRoleInstanceConfigEntity implements Serializable { /** * 服务角色实例id */ - private Integer service_role_instance_id; + @TableField("service_role_instance_id") + private Integer serviceRoleInstanceId; + /** * 创建时间 */ - private Date create_time; + @TableField("create_time") + private Date createTime; + /** * 配置json */ - private String config_json; + @TableField("config_json") + private String configJson; /** * 更新时间 */ - private Date update_time; + @TableField("update_time") + private Date updateTime; + /** * 配置json md5 */ - private String config_json_md5; + @TableField("config_json_md5") + private String configJsonMd5; + /** * 配置json版本 */ - private String config_json_version; - + @TableField("config_json_version") + private String configJsonVersion; + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceEntity.java index e297c108..8c4196c8 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceEntity.java @@ -33,9 +33,9 @@ @TableName("t_ddh_cluster_service_role_instance") @Data public class ClusterServiceRoleInstanceEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -53,7 +53,7 @@ public class ClusterServiceRoleInstanceEntity implements Serializable { * 服务角色状态 1:正在运行 2:停止 3:存在告警 4:退役中 5:已退役 */ private ServiceRoleState serviceRoleState; - + @TableField(exist = false) private Integer serviceRoleStateCode; /** @@ -80,12 +80,12 @@ public class ClusterServiceRoleInstanceEntity implements Serializable { * 服务名称 */ private String serviceName; - + private Integer roleGroupId; - + private NeedRestart needRestart; - + @TableField(exist = false) private String roleGroupName; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceWebuis.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceWebuis.java index af7742bc..8b0a01b2 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceWebuis.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterServiceRoleInstanceWebuis.java @@ -27,9 +27,9 @@ @Data @TableName("t_ddh_cluster_service_role_instance_webuis") public class ClusterServiceRoleInstanceWebuis implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -43,9 +43,9 @@ public class ClusterServiceRoleInstanceWebuis implements Serializable { * URL地址 */ private String webUrl; - + private Integer serviceInstanceId; - + private String name; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUser.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUser.java index 88fc09e8..51c831cc 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUser.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUser.java @@ -28,20 +28,20 @@ @Data @TableName("t_ddh_cluster_user") public class ClusterUser implements Serializable { - + private static final long serialVersionUID = 1L; - + @TableId private Integer id; - + private String username; - + private Integer clusterId; - + @TableField(exist = false) private String mainGroup; - + @TableField(exist = false) private String otherGroups; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUserGroup.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUserGroup.java index e412b286..40f78bb2 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUserGroup.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterUserGroup.java @@ -27,9 +27,9 @@ @Data @TableName("t_ddh_cluster_user_group") public class ClusterUserGroup implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -43,9 +43,9 @@ public class ClusterUserGroup implements Serializable { * */ private Integer groupId; - + private Integer clusterId; - + private Integer userGroupType; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterVariable.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterVariable.java index 81525458..ef4a81ad 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterVariable.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterVariable.java @@ -17,18 +17,19 @@ package com.datasophon.dao.entity; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; + import lombok.Data; -import java.io.Serializable; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; @Data @TableName("t_ddh_cluster_variable") public class ClusterVariable implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -46,10 +47,10 @@ public class ClusterVariable implements Serializable { * */ private String variableValue; - + /** * */ private String serviceName; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnQueue.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnQueue.java index 64a96892..04c0bd91 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnQueue.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnQueue.java @@ -29,9 +29,9 @@ @Data @TableName("t_ddh_cluster_yarn_queue") public class ClusterYarnQueue implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -73,17 +73,17 @@ public class ClusterYarnQueue implements Serializable { * 1: true 2:false */ private Integer allowPreemption; - + private Integer clusterId; - + private Date createTime; - + private String amShare; - + @TableField(exist = false) private String minResources; - + @TableField(exist = false) private String maxResources; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnScheduler.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnScheduler.java index 6435369f..02672716 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnScheduler.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterYarnScheduler.java @@ -27,9 +27,9 @@ @Data @TableName("t_ddh_cluster_yarn_scheduler") public class ClusterYarnScheduler implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -43,7 +43,7 @@ public class ClusterYarnScheduler implements Serializable { * */ private String scheduler; - + private Integer inUse; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterZk.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterZk.java index cf23a986..9b83271e 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterZk.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/ClusterZk.java @@ -27,9 +27,9 @@ @Data @TableName("t_ddh_cluster_zk") public class ClusterZk implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -47,5 +47,5 @@ public class ClusterZk implements Serializable { * */ private Integer clusterId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameInfoEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameInfoEntity.java index eab3afdd..6a2bd64c 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameInfoEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameInfoEntity.java @@ -29,9 +29,9 @@ @Data @TableName("t_ddh_frame_info") public class FrameInfoEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -49,8 +49,8 @@ public class FrameInfoEntity implements Serializable { * 框架版本 */ private String frameVersion; - + @TableField(exist = false) private List frameServiceList; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceEntity.java index 687f0b48..3808db4f 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceEntity.java @@ -30,9 +30,9 @@ @Data @Accessors(chain = true) public class FrameServiceEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -46,7 +46,7 @@ public class FrameServiceEntity implements Serializable { * 服务名称 */ private String serviceName; - + private String label; /** * 服务版本 @@ -56,28 +56,28 @@ public class FrameServiceEntity implements Serializable { * 服务描述 */ private String serviceDesc; - + private String packageName; - + private String dependencies; - + private String serviceJson; - + private String serviceJsonMd5; - + private String serviceConfig; - + private String frameCode; - + private String configFileJson; - + private String configFileJsonMd5; - + private String decompressPackageName; - + @TableField(exist = false) private Boolean installed; - + private Integer sortNum; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceRoleEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceRoleEntity.java index bcd460c5..e7cb3f6a 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceRoleEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/FrameServiceRoleEntity.java @@ -33,9 +33,9 @@ @Data @Accessors(chain = true) public class FrameServiceRoleEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -57,18 +57,18 @@ public class FrameServiceRoleEntity implements Serializable { * 1 1+ */ private String cardinality; - + private String serviceRoleJson; - + private String serviceRoleJsonMd5; - + private String frameCode; - + private String jmxPort; - + @TableField(exist = false) private List hosts; - + private String logFile; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/InstallStepEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/InstallStepEntity.java index f6258aff..20e2d868 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/InstallStepEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/InstallStepEntity.java @@ -27,9 +27,9 @@ @TableName("t_ddh_install_step") @Data public class InstallStepEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -43,5 +43,5 @@ public class InstallStepEntity implements Serializable { * */ private String stepDesc; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupEntity.java index 9d023ef1..4f3b80c2 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupEntity.java @@ -25,9 +25,9 @@ @TableName("t_ddh_notice_group") public class NoticeGroupEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -41,5 +41,5 @@ public class NoticeGroupEntity implements Serializable { * 创建时间 */ private Date createTime; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupUserEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupUserEntity.java index 1101ac34..8014b2db 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupUserEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/NoticeGroupUserEntity.java @@ -24,9 +24,9 @@ @TableName("t_ddh_notice_group_user") public class NoticeGroupUserEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -40,5 +40,5 @@ public class NoticeGroupUserEntity implements Serializable { * 用户id */ private Integer userId; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/RoleInfoEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/RoleInfoEntity.java index 79adc499..de8379bc 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/RoleInfoEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/RoleInfoEntity.java @@ -28,9 +28,9 @@ @Data @TableName("t_ddh_role_info") public class RoleInfoEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -48,5 +48,5 @@ public class RoleInfoEntity implements Serializable { * 创建时间 */ private Date createTime; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/SessionEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/SessionEntity.java index b81661dc..6c0691d7 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/SessionEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/SessionEntity.java @@ -28,9 +28,9 @@ @Data @TableName("t_ddh_session") public class SessionEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * */ @@ -48,5 +48,5 @@ public class SessionEntity implements Serializable { * */ private Date lastLoginTime; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/UserInfoEntity.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/UserInfoEntity.java index bc9f1a05..b05ab01e 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/UserInfoEntity.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/entity/UserInfoEntity.java @@ -28,9 +28,9 @@ @Data @TableName("t_ddh_user_info") public class UserInfoEntity implements Serializable { - + private static final long serialVersionUID = 1L; - + /** * 主键 */ @@ -56,7 +56,7 @@ public class UserInfoEntity implements Serializable { * 创建时间 */ private Date createTime; - + private Integer userType; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/AlertLevel.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/AlertLevel.java index ee497657..30983782 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/AlertLevel.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/AlertLevel.java @@ -21,37 +21,37 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum AlertLevel { - + WARN(1, "warning"), EXCEPTION(2, "exception"); - + @EnumValue private int value; - + private String desc; - + AlertLevel(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ClusterState.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ClusterState.java index 437868ea..fe83efcf 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ClusterState.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ClusterState.java @@ -17,51 +17,51 @@ package com.datasophon.dao.enums; +import java.util.Arrays; + import com.baomidou.mybatisplus.annotation.EnumValue; import com.fasterxml.jackson.annotation.JsonValue; -import java.util.Arrays; - public enum ClusterState { - + DELETING(4, "删除中"), - + STOP(3, "停止"), - + RUNNING(2, "正在运行"), NEED_CONFIG(1, "待配置"); - + @EnumValue private int value; - + private String desc; - + ClusterState(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + public static ClusterState of(int value) { return Arrays.stream(values()).filter(state -> state.getValue() == value).findAny().orElse(null); } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/CommandState.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/CommandState.java index c657ff12..b091d4fe 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/CommandState.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/CommandState.java @@ -21,41 +21,41 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum CommandState { - + // 命令状态 1:正在运行2:成功3:失败 WAIT(0, "待运行"), RUNNING(1, "正在运行"), SUCCESS(2, "成功"), FAILED(3, "失败"), CANCEL(4, "取消"); - + @EnumValue private int value; - + private String desc; - + CommandState(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/NeedRestart.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/NeedRestart.java index 87c1d3ef..a451b595 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/NeedRestart.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/NeedRestart.java @@ -21,35 +21,35 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum NeedRestart { - + NO(1, false), YES(2, true); - + @EnumValue private int value; - + private boolean desc; - + NeedRestart(int value, boolean desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public boolean isDesc() { return desc; } - + public void setDesc(boolean desc) { this.desc = desc; } - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/QuotaState.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/QuotaState.java index 7ab976be..446ef906 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/QuotaState.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/QuotaState.java @@ -21,38 +21,38 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum QuotaState { - + RUNNING(1, "启用"), STOPPED(2, "未启用"), WAIT_TO_UPDATE(3, "待更新"); - + @EnumValue private int value; - + private String desc; - + QuotaState(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/RoleType.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/RoleType.java index a51248b7..fcdad475 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/RoleType.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/RoleType.java @@ -21,38 +21,39 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum RoleType { - + MASTER(1, "master"), WORKER(2, "worker"), CLIENT(3, "client"), SLAVE(4, "slave"); - + @EnumValue private int value; - + private String desc; - + RoleType(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceRoleState.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceRoleState.java index b3a516fa..b05bfa3e 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceRoleState.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceRoleState.java @@ -21,40 +21,40 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum ServiceRoleState { - + RUNNING(1, "正在运行"), STOP(2, "停止"), EXISTS_ALARM(3, "存在告警"), DECOMMISSIONING(4, "退役中"), DECOMMISSIONED(5, "已退役"); - + @EnumValue private int value; - + private String desc; - + ServiceRoleState(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceState.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceState.java index deaf1bea..7f3bf49a 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceState.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/ServiceState.java @@ -21,40 +21,40 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum ServiceState { - + WAIT_INSTALL(1, "待安装"), RUNNING(2, "正常"), EXISTS_ALARM(3, "存在告警"), EXISTS_EXCEPTION(4, "存在异常"), ; - + @EnumValue private int value; - + private String desc; - + ServiceState(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/UserType.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/UserType.java index 0c0a4560..021933e4 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/UserType.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/enums/UserType.java @@ -21,36 +21,36 @@ import com.fasterxml.jackson.annotation.JsonValue; public enum UserType { - + CLUSTER_MANAGER(1, "集群管理员"); - + @EnumValue private int value; - + private String desc; - + UserType(int value, String desc) { this.value = value; this.desc = desc; } - + public int getValue() { return value; } - + public void setValue(int value) { this.value = value; } - + @JsonValue public String getDesc() { return desc; } - + public void setDesc(String desc) { this.desc = desc; } - + @Override public String toString() { return this.desc; diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/AlertGroupMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/AlertGroupMapper.java index 2999997c..d2fde79c 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/AlertGroupMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/AlertGroupMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface AlertGroupMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertExpressionMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertExpressionMapper.java index 5b190ba4..ee7e8768 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertExpressionMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertExpressionMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterAlertExpressionMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertGroupMapMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertGroupMapMapper.java index ba71412d..5c866836 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertGroupMapMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertGroupMapMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterAlertGroupMapMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertHistoryMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertHistoryMapper.java index 09b215c4..ab548921 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertHistoryMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertHistoryMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterAlertHistoryMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertQuotaMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertQuotaMapper.java index 392395af..746bd90c 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertQuotaMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertQuotaMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterAlertQuotaMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertRuleMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertRuleMapper.java index 4a00b958..5640a07d 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertRuleMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterAlertRuleMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterAlertRuleMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterGroupMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterGroupMapper.java index 10f49350..31198b77 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterGroupMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterGroupMapper.java @@ -25,5 +25,5 @@ @Mapper public interface ClusterGroupMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterHostMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterHostMapper.java index 5e83de5d..c4aa43fb 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterHostMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterHostMapper.java @@ -33,8 +33,8 @@ */ @Mapper public interface ClusterHostMapper extends BaseMapper { - + ClusterHostDO getClusterHostByHostname(@Param("hostname") String hostname); - + void updateBatchNodeLabel(@Param("hostIds") String hostIds, @Param("nodeLabel") String nodeLabel); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterInfoMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterInfoMapper.java index 282ddc8d..689c61b1 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterInfoMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterInfoMapper.java @@ -33,6 +33,6 @@ */ @Mapper public interface ClusterInfoMapper extends BaseMapper { - + ClusterInfoEntity getClusterByClusterCode(@Param("clusterCode") String clusterCode); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterQueueCapacityMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterQueueCapacityMapper.java index 85d9d6b1..f8448431 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterQueueCapacityMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterQueueCapacityMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterQueueCapacityMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRackMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRackMapper.java index a3063b9f..c346c465 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRackMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRackMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterRackMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRoleUserMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRoleUserMapper.java index 01a6a0e5..bcb5794f 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRoleUserMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterRoleUserMapper.java @@ -36,6 +36,6 @@ */ @Mapper public interface ClusterRoleUserMapper extends BaseMapper { - + List getAllClusterManagerByClusterId(@Param("clusterId") Integer clusterId); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostCommandMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostCommandMapper.java index 998be9d3..a1c88b40 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostCommandMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostCommandMapper.java @@ -33,7 +33,7 @@ */ @Mapper public interface ClusterServiceCommandHostCommandMapper extends BaseMapper { - + Integer getHostCommandTotalProgressByHostnameAndCommandHostId(@Param("hostname") String hostname, @Param("commandHostId") String commandHostId); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostMapper.java index 01c3f0a8..cb973a02 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandHostMapper.java @@ -33,6 +33,6 @@ */ @Mapper public interface ClusterServiceCommandHostMapper extends BaseMapper { - + Integer getCommandHostTotalProgressByCommandId(@Param("commandId") String commandId); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandMapper.java index ec8fa9dd..eb1bfe05 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceCommandMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterServiceCommandMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceDashboardMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceDashboardMapper.java index 35857f6c..e0acc0a1 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceDashboardMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceDashboardMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterServiceDashboardMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceConfigMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceConfigMapper.java index b5d6eb5e..adb859f8 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceConfigMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceConfigMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterServiceInstanceConfigMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceMapper.java index 0949bca3..b948118f 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceMapper.java @@ -33,7 +33,7 @@ */ @Mapper public interface ClusterServiceInstanceMapper extends BaseMapper { - + String getServiceConfigByClusterIdAndServiceName(@Param("clusterId") Integer clusterId, @Param("serviceName") String serviceName); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceRoleGroupMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceRoleGroupMapper.java index 4de52669..a4b5c56e 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceRoleGroupMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceInstanceRoleGroupMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterServiceInstanceRoleGroupMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleGroupConfigMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleGroupConfigMapper.java index 00624af1..d6e3f43f 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleGroupConfigMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleGroupConfigMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterServiceRoleGroupConfigMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceConfigMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceConfigMapper.java index 47182f74..0b9cdb76 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceConfigMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceConfigMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterServiceRoleInstanceConfigMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceMapper.java index 1adfe5f1..c7e83065 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceMapper.java @@ -33,8 +33,8 @@ */ @Mapper public interface ClusterServiceRoleInstanceMapper extends BaseMapper { - + void updateToNeedRestart(@Param("roleGroupId") Integer roleGroupId); - + void updateToNeedRestartByHost(@Param("hostName") String hostName); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceWebuisMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceWebuisMapper.java index 702f402e..968866db 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceWebuisMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterServiceRoleInstanceWebuisMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterServiceRoleInstanceWebuisMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserGroupMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserGroupMapper.java index a99eea69..a36c76cc 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserGroupMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserGroupMapper.java @@ -25,5 +25,5 @@ @Mapper public interface ClusterUserGroupMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserMapper.java index bfa35640..3d06ab65 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterUserMapper.java @@ -25,5 +25,5 @@ @Mapper public interface ClusterUserMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterVariableMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterVariableMapper.java index dc19243d..6541cdfc 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterVariableMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterVariableMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterVariableMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnQueueMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnQueueMapper.java index 8e24fa0d..5b5fdfc8 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnQueueMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnQueueMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterYarnQueueMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnSchedulerMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnSchedulerMapper.java index 2acc6498..e9cfa19f 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnSchedulerMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterYarnSchedulerMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface ClusterYarnSchedulerMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterZkMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterZkMapper.java index 6f0ef6d9..9c1f40fd 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterZkMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/ClusterZkMapper.java @@ -33,6 +33,6 @@ */ @Mapper public interface ClusterZkMapper extends BaseMapper { - + Integer getMaxMyId(@Param("clusterId") Integer clusterId); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameInfoMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameInfoMapper.java index 2cc7b3f2..aa6470a5 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameInfoMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameInfoMapper.java @@ -33,6 +33,6 @@ */ @Mapper public interface FrameInfoMapper extends BaseMapper { - + FrameInfoEntity getFrameInfoByFrameCode(@Param("frameCode") String frameCode); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceMapper.java index bc58c91b..35c52b51 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface FrameServiceMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceRoleMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceRoleMapper.java index 11850f7a..bf91ff15 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceRoleMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/FrameServiceRoleMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface FrameServiceRoleMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/InstallStepMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/InstallStepMapper.java index e27377a5..26816c38 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/InstallStepMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/InstallStepMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface InstallStepMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/NoticeGroupUserMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/NoticeGroupUserMapper.java index 6d4b15db..53c9d16f 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/NoticeGroupUserMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/NoticeGroupUserMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface NoticeGroupUserMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/RoleInfoMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/RoleInfoMapper.java index 6234512f..e5aed07e 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/RoleInfoMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/RoleInfoMapper.java @@ -32,5 +32,5 @@ */ @Mapper public interface RoleInfoMapper extends BaseMapper { - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/SessionMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/SessionMapper.java index 0cc2453d..c3db878b 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/SessionMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/SessionMapper.java @@ -35,10 +35,10 @@ */ @Mapper public interface SessionMapper extends BaseMapper { - + SessionEntity queryByUserIdAndIp(@Param("userId") Integer id, @Param("ip") String ip); - + List queryByUserId(@Param("userId") Integer id); - + void insertSession(SessionEntity session); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/UserInfoMapper.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/UserInfoMapper.java index cbca0a74..aa75e813 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/UserInfoMapper.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/mapper/UserInfoMapper.java @@ -33,6 +33,6 @@ */ @Mapper public interface UserInfoMapper extends BaseMapper { - + UserInfoEntity queryUserByToken(@Param("token") String token); } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ClusterQueueCapacityList.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ClusterQueueCapacityList.java index 9cc0c787..eeb268ba 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ClusterQueueCapacityList.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ClusterQueueCapacityList.java @@ -25,10 +25,10 @@ @Data public class ClusterQueueCapacityList { - + private String rootId; - + private List nodes; - + private List links; } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ComponentVO.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ComponentVO.java index 0ca65f76..a2cdb685 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ComponentVO.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ComponentVO.java @@ -28,35 +28,35 @@ */ @Data public class ComponentVO { - + String name; String label; String version; String packageName; String hash; String md5; - + /** * 系统架构,x86、x86_64、aarch64、RISC-V */ String arch; String description; - + /** * 支持的 frame 版本 */ String meta; - + /** * 当前阶段:下载(download)、验证(valid)、安装(install) */ String step; - + /** * 当前状态,executing, success, fail */ String state; - + /** * 下载进度:0 - 1 之间 */ diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/Links.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/Links.java index cda7fbbf..1c0a58e1 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/Links.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/Links.java @@ -21,8 +21,8 @@ @Data public class Links { - + private String from; - + private String to; } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ParcelInfoVO.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ParcelInfoVO.java index 0b053bb8..3e9f686e 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ParcelInfoVO.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ParcelInfoVO.java @@ -17,10 +17,10 @@ package com.datasophon.dao.model; -import lombok.Data; - import java.util.List; +import lombok.Data; + /** * * 第三方框架组件 @@ -30,45 +30,45 @@ */ @Data public class ParcelInfoVO { - + /** * Parcel Remote URL */ String url; - + /** * Parcel 名称 */ String parcelName; - + /** * hash 256 验证 */ String hash; - + /** * md5 验证 */ String md5; - + /** * 依赖的 DDP 版本 */ String depends; - + /** * 支持的 DDP Frame 框架版本 */ String meta; - + /** * 内部包含的组件 */ List components; - + /** * 最后修改时间 */ long lastUpdated; - + } diff --git a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ServiceOperateModel.java b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ServiceOperateModel.java index 3d08440b..ae6889a6 100644 --- a/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ServiceOperateModel.java +++ b/datasophon-infrastructure/src/main/java/com/datasophon/dao/model/ServiceOperateModel.java @@ -21,9 +21,9 @@ @Data public class ServiceOperateModel { - + private Integer commandType; - + private String serviceName; - + } diff --git a/datasophon-service/pom.xml b/datasophon-service/pom.xml index f1cafab1..ab96f209 100644 --- a/datasophon-service/pom.xml +++ b/datasophon-service/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 - datasophon com.datasophon + datasophon ${revision} - 4.0.0 datasophon-service @@ -22,8 +21,8 @@ fastjson - commons-lang - commons-lang + org.apache.commons + commons-lang3 commons-httpclient @@ -40,8 +39,8 @@ ${project.version} - slf4j-reload4j org.slf4j + slf4j-reload4j @@ -75,4 +74,4 @@ eddsa - \ No newline at end of file + diff --git a/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java b/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java index baab38ab..30f0787e 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java +++ b/datasophon-service/src/main/java/com/datasophon/api/enums/Status.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.api.enums; import com.alibaba.fastjson.JSONObject; @@ -22,11 +23,11 @@ * status enum */ public enum Status { - + SUCCESS(200, "success", "成功"), - + INTERNAL_SERVER_ERROR_ARGS(10000, "Internal Server Error: {0}", "服务端异常: {0}"), - + USER_NAME_EXIST(10003, "user name already exists", "用户名已存在"), USER_NAME_NULL(10004, "user name is null", "用户名不能为空"), USER_NOT_EXIST(10010, "user {0} not exists", "用户[{0}]不存在"), @@ -39,7 +40,7 @@ public enum Status { LOGIN_SUCCESS(10042, "login success", "登录成功"), IP_IS_EMPTY(10125, "ip is empty", "IP地址不能为空"), DELETE_USER_BY_ID_ERROR(10093, "delete user by id error", "删除用户错误"), - + START_CHECK_HOST(10000, "start check host", "开始主机校验"), CHECK_HOST_SUCCESS(10001, "check host success", "主机校验成功"), NEED_JAVA_ENVIRONMENT(10002, "need java environment", "缺少Java环境"), @@ -47,7 +48,7 @@ public enum Status { NEED_HOSTNAME(10004, "need hostname", "无法获取主机名"), CAN_NOT_GET_IP(10005, "can not get ip", "无法获取ip地址"), INSTALL_SERVICE(10006, "Install Service ", "安装服务"), - + CLUSTER_CODE_EXISTS(10007, "cluster code exists", "集群编码已存在"), ALERT_GROUP_TIPS_ONE(10008, "an alarm group has been bound to an alarm indicator, delete the bound alarm indicator first", @@ -87,30 +88,30 @@ public enum Status { "同一个服务在同一台机器上的所有实例需要在同一个角色组内"), ODD_NUMBER_ARE_REQUIRED_FOR_DORISFE(10040, "The Number of DorisFE must be an odd number.", "DorisFE个数必须是奇数"), NO_SERVICE_ROLE_SELECTED(10041, "No service role selected", "未选择需要安装的服务实例"), - TWO_KYUUBISERVERS_NEED_TO_BE_DEPLOYED(10042, "two kyuubiServer deployments are required", "KyuubiServer需要两个节点"),; - - + TWO_KYUUBISERVERS_NEED_TO_BE_DEPLOYED(10042, "two kyuubiServer deployments are required", "KyuubiServer需要两个节点"), + ; + private final int code; private final String enMsg; private final String zhMsg; - + Status(int code, String enMsg, String zhMsg) { this.code = code; this.enMsg = enMsg; this.zhMsg = zhMsg; } - + public int getCode() { return this.code; } - + public JSONObject toJson() { JSONObject json = new JSONObject(); json.put("code", this.code); json.put("msg", getMsg()); return json; } - + public String getMsg() { return this.zhMsg; } diff --git a/datasophon-service/src/main/java/com/datasophon/api/exceptions/BusinessException.java b/datasophon-service/src/main/java/com/datasophon/api/exceptions/BusinessException.java index 92aa555a..16f2f0bb 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/exceptions/BusinessException.java +++ b/datasophon-service/src/main/java/com/datasophon/api/exceptions/BusinessException.java @@ -1,8 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + package com.datasophon.api.exceptions; public class BusinessException extends RuntimeException { - + public BusinessException(String message) { super(message); - }; + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/exceptions/ServiceException.java b/datasophon-service/src/main/java/com/datasophon/api/exceptions/ServiceException.java index f7e5fe4a..8c35619e 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/exceptions/ServiceException.java +++ b/datasophon-service/src/main/java/com/datasophon/api/exceptions/ServiceException.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.api.exceptions; import com.datasophon.api.enums.Status; @@ -22,33 +23,33 @@ * service exception */ public class ServiceException extends RuntimeException { - + /** * code */ private Integer code; - + public ServiceException() { } - + public ServiceException(Status status) { super(status.getMsg()); this.code = status.getCode(); } - + public ServiceException(Integer code, String message) { super(message); this.code = code; } - + public ServiceException(String message) { super(message); } - + public Integer getCode() { return this.code; } - + public void setCode(Integer code) { this.code = code; } diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/ConfigBean.java b/datasophon-service/src/main/java/com/datasophon/api/load/ConfigBean.java index 2a0c8636..d90dfc3f 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/ConfigBean.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/ConfigBean.java @@ -25,8 +25,8 @@ @Component @Data public class ConfigBean { - + @Value("${server.port}") private String serverPort; - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/GlobalVariables.java b/datasophon-service/src/main/java/com/datasophon/api/load/GlobalVariables.java index a2c9d24b..d9083459 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/GlobalVariables.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/GlobalVariables.java @@ -4,18 +4,18 @@ import java.util.Map; public class GlobalVariables { - + // cluster variable private static Map> map = new HashMap<>(); - + public static void put(Integer key, Map value) { map.put(key, value); } - + public static Map get(Integer key) { return map.get(key); } - + public static boolean exists(String key) { return map.containsKey(key); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/LoadServiceMeta.java b/datasophon-service/src/main/java/com/datasophon/api/load/LoadServiceMeta.java index a53a1129..50d6748f 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/LoadServiceMeta.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/LoadServiceMeta.java @@ -19,22 +19,45 @@ package com.datasophon.api.load; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.file.FileReader; -import cn.hutool.crypto.SecureUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.datasophon.api.service.*; +import static com.datasophon.common.Constants.META_PATH; + +import com.datasophon.api.service.ClusterInfoService; +import com.datasophon.api.service.ClusterServiceInstanceRoleGroupService; +import com.datasophon.api.service.ClusterServiceInstanceService; +import com.datasophon.api.service.ClusterServiceRoleGroupConfigService; +import com.datasophon.api.service.ClusterVariableService; +import com.datasophon.api.service.FrameInfoService; +import com.datasophon.api.service.FrameServiceRoleService; +import com.datasophon.api.service.FrameServiceService; import com.datasophon.api.utils.CommonUtils; import com.datasophon.api.utils.PackageUtils; import com.datasophon.api.utils.ProcessUtils; import com.datasophon.common.Constants; -import com.datasophon.common.model.*; -import com.datasophon.dao.entity.*; -import org.apache.commons.lang.StringUtils; +import com.datasophon.common.model.ConfigWriter; +import com.datasophon.common.model.Generators; +import com.datasophon.common.model.ServiceConfig; +import com.datasophon.common.model.ServiceInfo; +import com.datasophon.common.model.ServiceRoleInfo; +import com.datasophon.dao.entity.ClusterInfoEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceEntity; +import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; +import com.datasophon.dao.entity.ClusterVariable; +import com.datasophon.dao.entity.FrameInfoEntity; +import com.datasophon.dao.entity.FrameServiceEntity; +import com.datasophon.dao.entity.FrameServiceRoleEntity; + +import org.apache.commons.lang3.StringUtils; + +import java.io.File; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; @@ -44,50 +67,52 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import java.io.File; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.*; -import java.util.stream.Collectors; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import static com.datasophon.common.Constants.META_PATH; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.file.FileReader; +import cn.hutool.crypto.SecureUtil; @Component public class LoadServiceMeta implements ApplicationRunner { - + private static final Logger logger = LoggerFactory.getLogger(LoadServiceMeta.class); - + @Autowired private FrameServiceService frameServiceService; - + @Autowired private FrameInfoService frameInfoService; - + @Autowired private FrameServiceRoleService roleService; - + @Autowired private ClusterVariableService variableService; - + @Autowired private ClusterInfoService clusterInfoService; - + @Autowired private ConfigBean configBean; - + @Autowired private ClusterServiceInstanceService serviceInstanceService; - + @Autowired private ClusterServiceInstanceRoleGroupService roleGroupService; - + @Autowired private ClusterServiceRoleGroupConfigService roleGroupConfigService; - + private static final String HDFS = "HDFS"; - + private static final String HADOOP = "HADOOP"; - + @Override @Transactional(rollbackFor = Exception.class) public void run(ApplicationArguments args) throws Exception { @@ -95,7 +120,7 @@ public void run(ApplicationArguments args) throws Exception { // load global variable, 加载 frame List clusters = clusterInfoService.list(); loadGlobalVariables(clusters); - + for (File path : ddps) { List files = FileUtil.loopFiles(path); String frameCode = path.getName(); @@ -114,8 +139,7 @@ public void run(ApplicationArguments args) throws Exception { } } } - - + /** * 解析 DDL 并存储到 frame 库 * @@ -132,7 +156,7 @@ public void parseServiceDdl(final String frameCode, final String serviceDdl) { ServiceInfo serviceInfo = JSONObject.parseObject(serviceDdl, ServiceInfo.class); String serviceInfoMd5 = SecureUtil.md5(serviceDdl); - + // save service config List allParameters = serviceInfo.getParameters(); Map map = @@ -143,12 +167,12 @@ public void parseServiceDdl(final String frameCode, serviceConfig -> serviceConfig, (v1, v2) -> v1)); Map> configFileMap = new HashMap<>(); - + buildConfigFileMap(serviceInfo, map, configFileMap); - + PackageUtils.putServicePackageName( frameCode, serviceName, serviceInfo.getDecompressPackageName()); - + putServiceHomeToVariable(frameCode, clusters, serviceName, serviceInfo.getDecompressPackageName()); // save service and service config @@ -165,13 +189,12 @@ public void parseServiceDdl(final String frameCode, // save frame service role saveFrameServiceRole(frameCode, serviceName, serviceInfo, serviceEntity); } - - + private void putServiceHomeToVariable(String frameCode, - List clusters, String serviceName, - String decompressPackageName) { + List clusters, String serviceName, + String decompressPackageName) { for (ClusterInfoEntity cluster : clusters) { - if(cluster.getClusterFrame().equals(frameCode)) { + if (cluster.getClusterFrame().equals(frameCode)) { Map globalVariables = GlobalVariables.get(cluster.getId()); if (HDFS.equals(serviceName)) { serviceName = HADOOP; @@ -182,14 +205,14 @@ private void putServiceHomeToVariable(String frameCode, } } } - + private void saveFrameServiceRole( - String frameCode, - String serviceName, - ServiceInfo serviceInfo, - FrameServiceEntity serviceEntity) { + String frameCode, + String serviceName, + ServiceInfo serviceInfo, + FrameServiceEntity serviceEntity) { List serviceRoles = serviceInfo.getRoles(); - + for (ServiceRoleInfo serviceRole : serviceRoles) { serviceRole.setParentName(serviceName); String key = @@ -242,16 +265,16 @@ private void saveFrameServiceRole( logger.info("put {} {} service info into cache", frameCode, serviceName); ServiceInfoMap.put(frameCode + Constants.UNDERLINE + serviceName, serviceInfo); } - + private FrameServiceEntity saveFrameService( - String frameCode, - FrameInfoEntity frameInfo, - String serviceName, - String serviceDdl, - ServiceInfo serviceInfo, - String serviceInfoMd5, - List allParameters, - Map> configFileMap) { + String frameCode, + FrameInfoEntity frameInfo, + String serviceName, + String serviceDdl, + ServiceInfo serviceInfo, + String serviceInfoMd5, + List allParameters, + Map> configFileMap) { FrameServiceEntity serviceEntity = frameServiceService.getServiceByFrameIdAndServiceName( frameInfo.getId(), serviceName); @@ -267,7 +290,7 @@ private FrameServiceEntity saveFrameService( serviceEntity, configFileMap, serviceInfo.getDecompressPackageName()); - + frameServiceService.save(serviceEntity); } else if (!serviceEntity.getServiceJsonMd5().equals(serviceInfoMd5)) { String configMapStr = JSONObject.toJSONString(configFileMap); @@ -289,21 +312,21 @@ private FrameServiceEntity saveFrameService( serviceInfo.getDecompressPackageName()); frameServiceService.updateById(serviceEntity); } - + ServiceConfigMap.put( frameCode + Constants.UNDERLINE + serviceInfo.getName() + Constants.CONFIG, allParameters); ServiceConfigFileMap.put( frameCode + Constants.UNDERLINE + serviceInfo.getName() + Constants.CONFIG_FILE, configFileMap); - + return serviceEntity; } - + private void buildConfigFileMap( - ServiceInfo serviceInfo, - Map map, - Map> configFileMap) { + ServiceInfo serviceInfo, + Map map, + Map> configFileMap) { ConfigWriter configWriter = serviceInfo.getConfigWriter(); List generators = configWriter.getGenerators(); for (Generators generator : generators) { @@ -324,7 +347,7 @@ private void buildConfigFileMap( } } } - + private FrameInfoEntity saveClusterFrame(String frameCode) { FrameInfoEntity frameInfo = frameInfoService.getOne( @@ -336,7 +359,7 @@ private FrameInfoEntity saveClusterFrame(String frameCode) { } return frameInfo; } - + public void loadGlobalVariables(List clusters) throws UnknownHostException { if (CollUtil.isNotEmpty(clusters)) { for (ClusterInfoEntity cluster : clusters) { @@ -351,16 +374,16 @@ public void loadGlobalVariables(List clusters) throws Unknown globalVariables.put("${apiHost}", InetAddress.getLocalHost().getHostName()); globalVariables.put("${apiPort}", configBean.getServerPort()); globalVariables.put("${INSTALL_PATH}", Constants.INSTALL_PATH); - + GlobalVariables.put(cluster.getId(), globalVariables); - + ProcessUtils.createServiceActor(cluster); } } } - + private void updateServiceInstanceConfig( - String frameCode, String serviceName, List parameters) { + String frameCode, String serviceName, List parameters) { // 查询frameCode相同的集群 List clusters = clusterInfoService.getClusterByFrameCode(frameCode); // 查询集群的服务实例 @@ -381,14 +404,14 @@ private void updateServiceInstanceConfig( } } } - + private void buildFrameServiceRole( - String frameCode, - FrameServiceEntity serviceEntity, - ServiceRoleInfo serviceRole, - String serviceRoleJson, - String serviceRoleJsonMd5, - FrameServiceRoleEntity role) { + String frameCode, + FrameServiceEntity serviceEntity, + ServiceRoleInfo serviceRole, + String serviceRoleJson, + String serviceRoleJsonMd5, + FrameServiceRoleEntity role) { role.setServiceId(serviceEntity.getId()); role.setServiceRoleName(serviceRole.getName()); role.setCardinality(serviceRole.getCardinality()); @@ -399,17 +422,17 @@ private void buildFrameServiceRole( role.setServiceRoleJsonMd5(serviceRoleJsonMd5); role.setLogFile(serviceRole.getLogFile()); } - + private void buildServiceEntity( - String frameCode, - Integer frameInfoId, - String serviceName, - String serviceDdl, - ServiceInfo serviceInfo, - String serviceInfoMd5, - FrameServiceEntity serviceEntity, - Map> configFileMap, - String decompressPackageName) { + String frameCode, + Integer frameInfoId, + String serviceName, + String serviceDdl, + ServiceInfo serviceInfo, + String serviceInfoMd5, + FrameServiceEntity serviceEntity, + Map> configFileMap, + String decompressPackageName) { serviceEntity.setServiceName(serviceName); serviceEntity.setLabel(serviceInfo.getLabel()); serviceEntity.setFrameId(frameInfoId); diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigFileMap.java b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigFileMap.java index 216d7940..dd70bce9 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigFileMap.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigFileMap.java @@ -25,18 +25,18 @@ import java.util.Map; public class ServiceConfigFileMap { - + private static HashMap>> map = new HashMap>>(); - + public static void put(String key, Map> configs) { map.put(key, configs); } - + public static Map> get(String key) { return map.get(key); } - + public static boolean exists(String key) { return map.containsKey(key); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigMap.java b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigMap.java index 7b3b37b9..8e5d647e 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigMap.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceConfigMap.java @@ -23,17 +23,17 @@ import java.util.List; public class ServiceConfigMap { - + private static HashMap> map = new HashMap>(); - + public static void put(String key, List configs) { map.put(key, configs); } - + public static List get(String key) { return map.get(key); } - + public static boolean exists(String key) { return map.containsKey(key); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceInfoMap.java b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceInfoMap.java index 977d2790..20b9a7f4 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceInfoMap.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceInfoMap.java @@ -22,17 +22,17 @@ import java.util.HashMap; public class ServiceInfoMap { - + private static HashMap map = new HashMap(); - + public static void put(String key, ServiceInfo value) { map.put(key, value); } - + public static ServiceInfo get(String key) { return map.get(key); } - + public static boolean exists(String key) { return map.containsKey(key); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleJmxMap.java b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleJmxMap.java index 583f4975..269651f7 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleJmxMap.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleJmxMap.java @@ -20,17 +20,17 @@ import java.util.HashMap; public class ServiceRoleJmxMap { - + private static HashMap map = new HashMap(); - + public static void put(String key, String value) { map.put(key, value); } - + public static String get(String key) { return map.get(key); } - + public static boolean exists(String key) { return map.containsKey(key); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleMap.java b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleMap.java index 90caa3ba..26dc8dc1 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleMap.java +++ b/datasophon-service/src/main/java/com/datasophon/api/load/ServiceRoleMap.java @@ -22,17 +22,17 @@ import java.util.HashMap; public class ServiceRoleMap { - + private static HashMap map = new HashMap(); - + public static void put(String key, ServiceRoleInfo value) { map.put(key, value); } - + public static ServiceRoleInfo get(String key) { return map.get(key); } - + public static boolean exists(String key) { return map.containsKey(key); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/ActorUtils.java b/datasophon-service/src/main/java/com/datasophon/api/master/ActorUtils.java index f2ec42f8..79e5c693 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/ActorUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/ActorUtils.java @@ -17,21 +17,14 @@ package com.datasophon.api.master; -import akka.actor.ActorRef; -import akka.actor.ActorSelection; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.util.Timeout; import com.datasophon.api.master.alert.ServiceRoleCheckActor; import com.datasophon.common.command.ClusterCommand; import com.datasophon.common.command.HostCheckCommand; import com.datasophon.common.command.ServiceRoleCheckCommand; import com.datasophon.common.enums.ClusterCommandType; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -45,21 +38,33 @@ import java.util.Random; import java.util.concurrent.TimeUnit; -public class ActorUtils { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(ActorUtils.class); +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; - public static ActorSystem actorSystem; +import akka.actor.ActorRef; +import akka.actor.ActorSelection; +import akka.actor.ActorSystem; +import akka.actor.Props; +import akka.util.Timeout; +public class ActorUtils { + + private static final Logger logger = LoggerFactory.getLogger(ActorUtils.class); + + public static ActorSystem actorSystem; + public static final String DATASOPHON = "datasophon"; - + public static final String AKKA_REMOTE_NETTY_TCP_HOSTNAME = "akka.remote.netty.tcp.hostname"; - + private static Random rand; - + private ActorUtils() throws NoSuchAlgorithmException { } - + public static void init() throws UnknownHostException, NoSuchAlgorithmException { String hostname = InetAddress.getLocalHost().getHostName(); Config config = ConfigFactory.parseString(AKKA_REMOTE_NETTY_TCP_HOSTNAME + "=" + hostname); @@ -71,10 +76,10 @@ public static void init() throws UnknownHostException, NoSuchAlgorithmException actorSystem.actorOf(Props.create(HostCheckActor.class), getActorRefName(HostCheckActor.class)); actorSystem.actorOf(Props.create(MasterNodeProcessingActor.class), getActorRefName(MasterNodeProcessingActor.class)); - + ActorRef clusterCheckActor = actorSystem.actorOf(Props.create(ClusterActor.class), getActorRefName(ClusterActor.class)); - + // 节点检测 5m 检测一次 actorSystem.scheduler().schedule( FiniteDuration.apply(30L, TimeUnit.SECONDS), @@ -83,7 +88,7 @@ public static void init() throws UnknownHostException, NoSuchAlgorithmException new HostCheckCommand(), actorSystem.dispatcher(), ActorRef.noSender()); - + actorSystem.scheduler().schedule( FiniteDuration.apply(15L, TimeUnit.SECONDS), FiniteDuration.apply(15L, TimeUnit.SECONDS), @@ -91,7 +96,7 @@ public static void init() throws UnknownHostException, NoSuchAlgorithmException new ServiceRoleCheckCommand(), actorSystem.dispatcher(), ActorRef.noSender()); - + // 集群检测 1m 检测一次 actorSystem.scheduler().schedule( FiniteDuration.apply(30L, TimeUnit.SECONDS), @@ -100,11 +105,10 @@ public static void init() throws UnknownHostException, NoSuchAlgorithmException new ClusterCommand(ClusterCommandType.CHECK), actorSystem.dispatcher(), ActorRef.noSender()); - - + rand = SecureRandom.getInstanceStrong(); } - + public static ActorRef getLocalActor(Class actorClass, String actorName) { ActorSelection actorSelection = actorSystem.actorSelection("/user/" + actorName); Timeout timeout = new Timeout(Duration.create(30, TimeUnit.SECONDS)); @@ -123,7 +127,7 @@ public static ActorRef getLocalActor(Class actorClass, String actorName) { } return actorRef; } - + private static ActorRef createActor(Class actorClass, String actorName) { ActorRef actorRef; try { @@ -134,10 +138,10 @@ private static ActorRef createActor(Class actorClass, String actorName) { actorRef = actorSystem.actorOf(Props.create(actorClass).withDispatcher("my-forkjoin-dispatcher"), actorName + num); } - + return actorRef; } - + public static ActorRef getRemoteActor(String hostname, String actorName) { String actorPath = "akka.tcp://datasophon@" + hostname + ":2552/user/worker/" + actorName; ActorSelection actorSelection = actorSystem.actorSelection(actorPath); @@ -149,10 +153,10 @@ public static ActorRef getRemoteActor(String hostname, String actorName) { } catch (Exception e) { logger.error(e.getMessage(), e); } - + return actorRef; } - + /** * shutdown */ @@ -165,12 +169,12 @@ public static void shutdown() { actorSystem = null; } } - + /** * Get ActorRef name from Class name. */ public static String getActorRefName(Class clazz) { return StringUtils.uncapitalize(clazz.getSimpleName()); } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/CancelCommandMap.java b/datasophon-service/src/main/java/com/datasophon/api/master/CancelCommandMap.java index c316605f..aae58673 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/CancelCommandMap.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/CancelCommandMap.java @@ -3,16 +3,17 @@ import java.util.HashMap; public class CancelCommandMap { + private static HashMap map = new HashMap(); - + public static void put(String key, String value) { map.put(key, value); } - + public static String get(String key) { return map.get(key); } - + public static boolean exists(String key) { return map.containsKey(key); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/ClusterActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/ClusterActor.java index 71571786..ea0bd01b 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/ClusterActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/ClusterActor.java @@ -17,10 +17,6 @@ package com.datasophon.api.master; -import akka.actor.UntypedActor; -import cn.hutool.core.date.DateUtil; -import cn.hutool.extra.spring.SpringUtil; -import com.alibaba.fastjson.JSONArray; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterServiceInstanceService; import com.datasophon.api.service.ClusterServiceRoleGroupConfigService; @@ -41,8 +37,6 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.ClusterState; import com.datasophon.dao.enums.ServiceRoleState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; @@ -50,16 +44,25 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.alibaba.fastjson.JSONArray; + +import akka.actor.UntypedActor; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.extra.spring.SpringUtil; /** * 节点状态监测 */ public class ClusterActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(ClusterActor.class); - + private static final String DEPRECATED = "Deprecated"; - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ClusterCommand) { @@ -68,47 +71,54 @@ public void onReceive(Object msg) throws Throwable { SpringUtil.getBean(ClusterServiceRoleInstanceService.class); ClusterInfoService clusterInfoService = SpringUtil.getBean(ClusterInfoService.class); - + // Host or cluster final ClusterCommand clusterCommand = (ClusterCommand) msg; - + if (ClusterCommandType.CHECK.equals(clusterCommand.getCommandType())) { // 获取所有集群 Result result = clusterInfoService.getClusterList(); List clusterList = (List) result.getData(); - + for (ClusterInfoEntity clusterInfoEntity : clusterList) { // 获取集群上正在运行的服务 int clusterId = clusterInfoEntity.getId(); - List roleInstanceList = roleInstanceService.getServiceRoleInstanceListByClusterId(clusterId); + List roleInstanceList = + roleInstanceService.getServiceRoleInstanceListByClusterId(clusterId); if (!ClusterState.NEED_CONFIG.equals(clusterInfoEntity.getClusterState())) { if (!roleInstanceList.isEmpty()) { - if (roleInstanceList.stream().allMatch(roleInstance -> ServiceRoleState.STOP.equals(roleInstance.getServiceRoleState()))) { + if (roleInstanceList.stream().allMatch( + roleInstance -> ServiceRoleState.STOP.equals(roleInstance.getServiceRoleState()))) { clusterInfoService.updateClusterState(clusterId, ClusterState.STOP.getValue()); } else { clusterInfoService.updateClusterState(clusterId, ClusterState.RUNNING.getValue()); } } - + } } - + } else if (ClusterCommandType.DELETE.equals(clusterCommand.getCommandType())) { Integer clusterId = clusterCommand.getClusterId(); if (Objects.nonNull(clusterId)) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); if (Objects.nonNull(clusterInfo)) { ClusterHostService clusterHostService = SpringUtil.getBean(ClusterHostService.class); - ClusterServiceInstanceService clusterServiceInstanceService = SpringUtil.getBean(ClusterServiceInstanceService.class); - ClusterServiceRoleInstanceService clusterServiceRoleInstanceService = SpringUtil.getBean(ClusterServiceRoleInstanceService.class); - ClusterServiceRoleGroupConfigService clusterServiceRoleGroupConfigService = SpringUtil.getBean(ClusterServiceRoleGroupConfigService.class); - + ClusterServiceInstanceService clusterServiceInstanceService = + SpringUtil.getBean(ClusterServiceInstanceService.class); + ClusterServiceRoleInstanceService clusterServiceRoleInstanceService = + SpringUtil.getBean(ClusterServiceRoleInstanceService.class); + ClusterServiceRoleGroupConfigService clusterServiceRoleGroupConfigService = + SpringUtil.getBean(ClusterServiceRoleGroupConfigService.class); + // 检查服务实例配置与目录 - List roleInstanceList = clusterServiceRoleInstanceService.getServiceRoleInstanceListByClusterId(clusterId); + List roleInstanceList = + clusterServiceRoleInstanceService.getServiceRoleInstanceListByClusterId(clusterId); for (ClusterServiceRoleInstanceEntity roleInstance : roleInstanceList) { String roleName = roleInstance.getServiceRoleName(); String hostname = roleInstance.getHostname(); - ClusterServiceRoleGroupConfig config = clusterServiceRoleGroupConfigService.getConfigByRoleGroupId(roleInstance.getRoleGroupId()); + ClusterServiceRoleGroupConfig config = clusterServiceRoleGroupConfigService + .getConfigByRoleGroupId(roleInstance.getRoleGroupId()); Map> configFileMap = new ConcurrentHashMap<>(); ProcessUtils.generateConfigFileMap(configFileMap, config, clusterId); for (Map.Entry> configFile : configFileMap.entrySet()) { @@ -118,17 +128,20 @@ public void onReceive(Object msg) throws Throwable { if (Constants.INPUT.equals(c.getType())) { String oldPath = (String) c.getValue(); if (!oldPath.contains(DEPRECATED)) { - String newPath = String.format("%s_%s_%s_%s", oldPath, DEPRECATED, clusterId, DateUtil.today()); + String newPath = String.format("%s_%s_%s_%s", oldPath, DEPRECATED, + clusterId, DateUtil.today()); c.setValue(newPath); c.setConfigType(Constants.MV_PATH); } } else if (Constants.MULTIPLE.equals(c.getType())) { JSONArray value = (JSONArray) c.getValue(); List oldPaths = value.toJavaList(String.class); - List newPaths = oldPaths.stream().map(path -> !path.contains(DEPRECATED) ? - String.format("%s_%s_%s_%s", path, DEPRECATED, clusterId, DateUtil.today()) - : path - ).collect(Collectors.toList()); + List newPaths = oldPaths.stream() + .map(path -> !path.contains(DEPRECATED) + ? String.format("%s_%s_%s_%s", path, DEPRECATED, + clusterId, DateUtil.today()) + : path) + .collect(Collectors.toList()); c.setValue(newPaths); c.setConfigType(Constants.MV_PATH); } @@ -141,7 +154,7 @@ public void onReceive(Object msg) throws Throwable { configFileMap.remove(configFile.getKey()); } } - + if (!configFileMap.isEmpty()) { // 分发重命名命令 ExecResult execResult = new ExecResult(); @@ -150,7 +163,8 @@ public void onReceive(Object msg) throws Throwable { "start to uninstall {} in host {}", roleName, hostname); - execResult = ProcessUtils.configServiceRoleInstance(clusterInfo, configFileMap, roleInstance); + execResult = ProcessUtils.configServiceRoleInstance(clusterInfo, configFileMap, + roleInstance); if (Objects.nonNull(execResult) && execResult.getExecResult()) { logger.info( "{} uninstall success in {}", @@ -163,7 +177,7 @@ public void onReceive(Object msg) throws Throwable { hostname); return; } - + } catch (Exception e) { logger.info( "{} uninstall failed in {}", @@ -174,10 +188,13 @@ public void onReceive(Object msg) throws Throwable { } } } - List serviceInstanceList = clusterServiceInstanceService.listAll(clusterId); - if (serviceInstanceList.stream().allMatch(instance -> clusterServiceInstanceService.delServiceInstance(instance.getId()).isSuccess())) { + List serviceInstanceList = + clusterServiceInstanceService.listAll(clusterId); + if (serviceInstanceList.stream().allMatch(instance -> clusterServiceInstanceService + .delServiceInstance(instance.getId()).isSuccess())) { List hostList = clusterHostService.getHostListByClusterId(clusterId); - clusterHostService.deleteHosts(hostList.stream().map(h -> String.valueOf(h.getId())).collect(Collectors.joining(Constants.COMMA))); + clusterHostService.deleteHosts(hostList.stream().map(h -> String.valueOf(h.getId())) + .collect(Collectors.joining(Constants.COMMA))); clusterInfoService.removeById(clusterId); } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/DAGBuildActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/DAGBuildActor.java index 52b4abc0..3eea6f57 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/DAGBuildActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/DAGBuildActor.java @@ -17,7 +17,11 @@ package com.datasophon.api.master; -import com.datasophon.api.service.*; +import com.datasophon.api.service.ClusterInfoService; +import com.datasophon.api.service.ClusterServiceCommandHostCommandService; +import com.datasophon.api.service.ClusterServiceCommandService; +import com.datasophon.api.service.FrameServiceRoleService; +import com.datasophon.api.service.FrameServiceService; import com.datasophon.api.strategy.ServiceRoleStrategy; import com.datasophon.api.strategy.ServiceRoleStrategyContext; import com.datasophon.api.utils.SpringTool; @@ -30,11 +34,19 @@ import com.datasophon.common.model.DAGGraph; import com.datasophon.common.model.ServiceNode; import com.datasophon.common.model.ServiceRoleInfo; -import com.datasophon.dao.entity.*; - -import org.apache.commons.lang.StringUtils; - -import java.util.*; +import com.datasophon.dao.entity.ClusterInfoEntity; +import com.datasophon.dao.entity.ClusterServiceCommandEntity; +import com.datasophon.dao.entity.ClusterServiceCommandHostCommandEntity; +import com.datasophon.dao.entity.FrameServiceEntity; +import com.datasophon.dao.entity.FrameServiceRoleEntity; + +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; @@ -47,18 +59,18 @@ import cn.hutool.core.util.ArrayUtil; public class DAGBuildActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(DAGBuildActor.class); - + @Override public void onReceive(Object message) throws Throwable { if (message instanceof StartExecuteCommandCommand) { DAGGraph dag = new DAGGraph<>(); - + StartExecuteCommandCommand executeCommandCommand = (StartExecuteCommandCommand) message; CommandType commandType = executeCommandCommand.getCommandType(); logger.info("start execute command"); - + ClusterServiceCommandService commandService = SpringTool.getApplicationContext().getBean(ClusterServiceCommandService.class); ClusterServiceCommandHostCommandService hostCommandService = @@ -68,11 +80,11 @@ public void onReceive(Object message) throws Throwable { FrameServiceService frameService = SpringTool.getApplicationContext().getBean(FrameServiceService.class); ClusterInfoService clusterInfoService = SpringTool.getApplicationContext().getBean(ClusterInfoService.class); - + ClusterInfoEntity clusterInfo = clusterInfoService.getById(executeCommandCommand.getClusterId()); List commandList = commandService.lambdaQuery() .in(ClusterServiceCommandEntity::getCommandId, executeCommandCommand.getCommandIds()).list(); - + ArrayList frameServiceList = new ArrayList<>(); if (ArrayUtil.isNotEmpty(commandList)) { for (ClusterServiceCommandEntity command : commandList) { @@ -80,21 +92,21 @@ public void onReceive(Object message) throws Throwable { List masterRoles = new ArrayList<>(); List elseRoles = new ArrayList<>(); ServiceNode serviceNode = new ServiceNode(); - + List hostCommandList = hostCommandService.getHostCommandListByCommandId(command.getCommandId()); - + FrameServiceEntity serviceEntity = frameService.getServiceByFrameCodeAndServiceName( clusterInfo.getClusterFrame(), command.getServiceName()); frameServiceList.add(serviceEntity); - + serviceNode.setCommandId(command.getCommandId()); for (ClusterServiceCommandHostCommandEntity hostCommand : hostCommandList) { logger.info("service role is {}", hostCommand.getServiceRoleName()); FrameServiceRoleEntity frameServiceRoleEntity = frameServiceRoleService.getServiceRoleByFrameCodeAndServiceRoleName( clusterInfo.getClusterFrame(), hostCommand.getServiceRoleName()); - + ServiceRoleInfo serviceRoleInfo = JSONObject .parseObject(frameServiceRoleEntity.getServiceRoleJson(), ServiceRoleInfo.class); serviceRoleInfo.setHostname(hostCommand.getHostname()); @@ -106,13 +118,13 @@ public void onReceive(Object message) throws Throwable { serviceRoleInfo.setCommandType(commandType); serviceRoleInfo.setServiceInstanceId(command.getServiceInstanceId()); serviceRoleInfo.setFrameCode(serviceEntity.getFrameCode()); - + ServiceRoleStrategy serviceRoleHandler = ServiceRoleStrategyContext.getServiceRoleHandler(serviceRoleInfo.getName()); if (Objects.nonNull(serviceRoleHandler)) { serviceRoleHandler.handlerServiceRoleInfo(serviceRoleInfo, hostCommand.getHostname()); } - + if (ServiceRoleType.MASTER.equals(serviceRoleInfo.getRoleType())) { masterRoles.add(serviceRoleInfo); } else { @@ -134,23 +146,23 @@ public void onReceive(Object message) throws Throwable { } } } - + if (commandType == CommandType.STOP_SERVICE) { logger.info("reverse dag"); dag = dag.getReverseDagGraph(dag); } - + Map errorTaskList = new ConcurrentHashMap<>(); Map activeTaskList = new ConcurrentHashMap<>(); Map readyToSubmitTaskList = new ConcurrentHashMap<>(); Map completeTaskList = new ConcurrentHashMap<>(); - + Collection beginNode = dag.getBeginNode(); logger.info("beginNode is {}", beginNode.toString()); for (String node : beginNode) { readyToSubmitTaskList.put(node, ""); } - + SubmitActiveTaskNodeCommand submitActiveTaskNodeCommand = new SubmitActiveTaskNodeCommand(); submitActiveTaskNodeCommand.setCommandType(executeCommandCommand.getCommandType()); submitActiveTaskNodeCommand.setDag(dag); @@ -160,7 +172,7 @@ public void onReceive(Object message) throws Throwable { submitActiveTaskNodeCommand.setReadyToSubmitTaskList(readyToSubmitTaskList); submitActiveTaskNodeCommand.setCompleteTaskList(completeTaskList); submitActiveTaskNodeCommand.setClusterCode(clusterInfo.getClusterCode()); - + ActorRef submitTaskNodeActor = ActorUtils.getLocalActor(SubmitTaskNodeActor.class, ActorUtils.getActorRefName(SubmitTaskNodeActor.class)); submitTaskNodeActor.tell(submitActiveTaskNodeCommand, getSelf()); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/DispatcherWorkerActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/DispatcherWorkerActor.java index 7ac37809..8007d384 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/DispatcherWorkerActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/DispatcherWorkerActor.java @@ -19,7 +19,6 @@ package com.datasophon.api.master; -import cn.hutool.core.io.FileUtil; import com.datasophon.api.master.handler.host.CheckWorkerMd5Handler; import com.datasophon.api.master.handler.host.DecompressWorkerHandler; import com.datasophon.api.master.handler.host.DispatcherWorkerHandlerChain; @@ -34,30 +33,32 @@ import com.datasophon.common.command.DispatcherHostAgentCommand; import com.datasophon.common.enums.InstallState; import com.datasophon.common.model.HostInfo; - import com.datasophon.common.utils.HostUtils; + import org.apache.sshd.client.session.ClientSession; import scala.Option; +import java.nio.charset.Charset; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import akka.actor.UntypedActor; -import cn.hutool.core.util.ObjectUtil; -import java.nio.charset.Charset; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ObjectUtil; public class DispatcherWorkerActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(DispatcherWorkerActor.class); - + @Override public void preRestart(Throwable reason, Option message) throws Exception { logger.info("host actor restart because {}", reason.getMessage()); super.preRestart(reason, message); } - + @Override public void onReceive(Object message) throws Throwable { DispatcherHostAgentCommand command = (DispatcherHostAgentCommand) message; @@ -72,23 +73,25 @@ public void onReceive(Object message) throws Throwable { MinaUtils.openConnection( hostInfo.getHostname(), hostInfo.getSshPort(), hostInfo.getSshUser()); DispatcherWorkerHandlerChain handlerChain = new DispatcherWorkerHandlerChain(); - if(localIp.equals(hostInfo.getIp())){ + if (localIp.equals(hostInfo.getIp())) { String currDir = System.getProperty("user.dir"); - String executeShellPath = currDir+ Constants.SHELL_SCRIPT_PATH + Constants.SLASH+Constants.DISPATCHER_WORK; + String executeShellPath = + currDir + Constants.SHELL_SCRIPT_PATH + Constants.SLASH + Constants.DISPATCHER_WORK; logger.info("start dispatcher manage node host agent,execute shell path :{}", executeShellPath); String md5 = FileUtil.readString( Constants.MASTER_MANAGE_PACKAGE_PATH + Constants.SLASH + - Constants.WORKER_PACKAGE_NAME + ".md5", Charset.defaultCharset()).trim(); - int exeCode = ExecuteShellScriptUtils.executeShellScript(executeShellPath,md5); - if(0 == exeCode){ + Constants.WORKER_PACKAGE_NAME + ".md5", + Charset.defaultCharset()).trim(); + int exeCode = ExecuteShellScriptUtils.executeShellScript(executeShellPath, md5); + if (0 == exeCode) { logger.info("distribution datasophon-worker.tar.gz success"); logger.info("md5.verification datasophon-worker.tar.gz success"); logger.info("decompress datasophon-worker.tar.gz success"); hostInfo.setProgress(50); hostInfo.setMessage(MessageResolverUtils .getMessage("installation.package.decompressed.success.and.modify.configuration.file")); - }else { + } else { logger.error("dispatcher manage node host agent failed"); hostInfo.setErrMsg("dispatcher manage node host agent failed"); hostInfo.setMessage(MessageResolverUtils @@ -96,13 +99,13 @@ public void onReceive(Object message) throws Throwable { CommonUtils.updateInstallState(InstallState.FAILED, hostInfo); throw new RuntimeException("---- dispatcher manage node host agent failed ----"); } - - }else { + + } else { handlerChain.addHandler(new UploadWorkerHandler()); handlerChain.addHandler(new CheckWorkerMd5Handler()); handlerChain.addHandler(new DecompressWorkerHandler()); } - + handlerChain.addHandler(new InstallJDKHandler()); handlerChain.addHandler( new StartWorkerHandler(command.getClusterId(), command.getClusterFrame())); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/HdfsECActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/HdfsECActor.java index e5c5456e..b95e44a2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/HdfsECActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/HdfsECActor.java @@ -36,9 +36,9 @@ * Used to manage hdfs capacity expansion and reduction */ public class HdfsECActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(HdfsECActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof HdfsEcCommand) { @@ -58,5 +58,5 @@ public void onReceive(Object msg) throws Throwable { unhandled(msg); } } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/HostCheckActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/HostCheckActor.java index 3d8f304b..aaf660a8 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/HostCheckActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/HostCheckActor.java @@ -17,14 +17,9 @@ package com.datasophon.api.master; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import akka.pattern.Patterns; -import akka.util.Timeout; -import cn.hutool.extra.spring.SpringUtil; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.common.command.HostCheckCommand; import com.datasophon.common.command.PingCommand; import com.datasophon.common.model.HostInfo; @@ -36,9 +31,9 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.domain.host.enums.HostState; import com.datasophon.domain.host.enums.MANAGED; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -49,138 +44,148 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import akka.actor.ActorRef; +import akka.actor.UntypedActor; +import akka.pattern.Patterns; +import akka.util.Timeout; +import cn.hutool.extra.spring.SpringUtil; /** * 节点状态监测 */ public class HostCheckActor extends UntypedActor { - - private static final Logger logger = LoggerFactory.getLogger(HostCheckActor.class); - - @Override - public void onReceive(Object msg) throws Throwable { - if (msg instanceof HostCheckCommand) { - logger.info("start to check host info"); - ClusterHostService clusterHostService = - SpringUtil.getBean(ClusterHostService.class); - ClusterServiceRoleInstanceService roleInstanceService = - SpringUtil.getBean(ClusterServiceRoleInstanceService.class); - ClusterInfoService clusterInfoService = - SpringUtil.getBean(ClusterInfoService.class); - - // Host or cluster - final HostCheckCommand hostCheckCommand = (HostCheckCommand) msg; - final HostInfo hostInfo = hostCheckCommand.getHostInfo(); - - // 获取当前安装并且正在运行的集群 - Result result = clusterInfoService.runningClusterList(); - List clusterList = (List) result.getData(); - - for (ClusterInfoEntity clusterInfoEntity : clusterList) { - // 获取集群上安装的 Prometheus 服务, 从 Prometheus 获取CPU、磁盘使用量等 - ClusterServiceRoleInstanceEntity prometheusInstance = - roleInstanceService.getOneServiceRole("Prometheus", "", clusterInfoEntity.getId()); - if (Objects.nonNull(prometheusInstance)) { - // 集群正常安装了 Prometheus - List list = clusterHostService.getHostListByClusterId(clusterInfoEntity.getId()); - String promUrl = "http://" + prometheusInstance.getHostname() + ":9090/api/v1/query"; - for (ClusterHostDO clusterHostDO : list) { - if (hostInfo != null && !StringUtils.equals(clusterHostDO.getHostname(), hostInfo.getHostname())) { - // 指定了节点,直接只处理这一个节点的 - continue; + + private static final Logger logger = LoggerFactory.getLogger(HostCheckActor.class); + + @Override + public void onReceive(Object msg) throws Throwable { + if (msg instanceof HostCheckCommand) { + logger.info("start to check host info"); + ClusterHostService clusterHostService = + SpringUtil.getBean(ClusterHostService.class); + ClusterServiceRoleInstanceService roleInstanceService = + SpringUtil.getBean(ClusterServiceRoleInstanceService.class); + ClusterInfoService clusterInfoService = + SpringUtil.getBean(ClusterInfoService.class); + + // Host or cluster + final HostCheckCommand hostCheckCommand = (HostCheckCommand) msg; + final HostInfo hostInfo = hostCheckCommand.getHostInfo(); + + // 获取当前安装并且正在运行的集群 + Result result = clusterInfoService.runningClusterList(); + List clusterList = (List) result.getData(); + + for (ClusterInfoEntity clusterInfoEntity : clusterList) { + // 获取集群上安装的 Prometheus 服务, 从 Prometheus 获取CPU、磁盘使用量等 + ClusterServiceRoleInstanceEntity prometheusInstance = + roleInstanceService.getOneServiceRole("Prometheus", "", clusterInfoEntity.getId()); + if (Objects.nonNull(prometheusInstance)) { + // 集群正常安装了 Prometheus + List list = clusterHostService.getHostListByClusterId(clusterInfoEntity.getId()); + String promUrl = "http://" + prometheusInstance.getHostname() + ":9090/api/v1/query"; + for (ClusterHostDO clusterHostDO : list) { + if (hostInfo != null + && !StringUtils.equals(clusterHostDO.getHostname(), hostInfo.getHostname())) { + // 指定了节点,直接只处理这一个节点的 + continue; + } + try { + String hostname = clusterHostDO.getHostname(); + // 查询内存总量 + String totalMemPromQl = "node_memory_MemTotal_bytes{job=~\"node\",instance=\"" + hostname + + ":9100\"}/1024/1024/1024"; + String totalMemStr = PromInfoUtils.getSinglePrometheusMetric(promUrl, totalMemPromQl); + if (StringUtils.isNotBlank(totalMemStr)) { + int totalMem = Double.valueOf(totalMemStr).intValue(); + clusterHostDO.setTotalMem(totalMem); + } + // 查询内存使用量 + String memAvailablePromQl = "node_memory_MemAvailable_bytes{job=~\"node\",instance=\"" + + hostname + ":9100\"}/1024/1024/1024"; + String memAvailableStr = + PromInfoUtils.getSinglePrometheusMetric(promUrl, memAvailablePromQl); + if (StringUtils.isNotBlank(memAvailableStr)) { + int memAvailable = Double.valueOf(memAvailableStr).intValue(); + Integer memUsed = clusterHostDO.getTotalMem() - memAvailable; + clusterHostDO.setUsedMem(memUsed); + } + // 总磁盘容量 + String totalDistPromQl = "sum(node_filesystem_size_bytes{instance=\"" + hostname + + ":9100\",fstype=~\"ext4|xfs\",mountpoint !~\".*pod.*\"})/1024/1024/1024"; + String totalDiskStr = PromInfoUtils.getSinglePrometheusMetric(promUrl, totalDistPromQl); + if (StringUtils.isNotBlank(totalDiskStr)) { + int totalDisk = Double.valueOf(totalDiskStr).intValue(); + clusterHostDO.setTotalDisk(totalDisk); + } + // 查询磁盘使用量 + String diskUsedPromQl = "sum(node_filesystem_size_bytes{instance=\"" + hostname + + ":9100\",fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}-node_filesystem_free_bytes{instance=\"" + + hostname + + ":9100\",fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"})/1024/1024/1024"; + String diskUsed = PromInfoUtils.getSinglePrometheusMetric(promUrl, diskUsedPromQl); + if (StringUtils.isNotBlank(diskUsed)) { + clusterHostDO.setUsedDisk(Double.valueOf(diskUsed).intValue()); + } + // 查询cpu负载 + String cpuLoadPromQl = "node_load5{job=~\"node\",instance=\"" + hostname + ":9100\"}"; + String cpuLoad = PromInfoUtils.getSinglePrometheusMetric(promUrl, cpuLoadPromQl); + if (StringUtils.isNotBlank(cpuLoad)) { + clusterHostDO.setAverageLoad(cpuLoad); + } + } catch (Exception e) { + logger.warn("check cluster state error, cause: {}", e.getMessage()); + } + } + if (!list.isEmpty()) { + clusterHostService.updateBatchById(list); + } + } else { + // 没有 Prometheus?直接获取节点,通过 rpc 检测是否启动 + List hosts = clusterHostService.getHostListByClusterId(clusterInfoEntity.getId()); + List checkedHosts = new ArrayList<>(hosts.size()); + for (ClusterHostDO host : hosts) { + if (hostInfo != null && !StringUtils.equals(host.getHostname(), hostInfo.getHostname())) { + // 指定了节点,直接只处理这一个节点的 + continue; + } + // copy 一个新的,只更新状态 + ClusterHostDO checkedHost = new ClusterHostDO(); + checkedHost.setId(host.getId()); + checkedHost.setCheckTime(new Date()); + try { + // rpc 检测 + final ActorRef pingActor = ActorUtils.getRemoteActor(host.getHostname(), "pingActor"); + PingCommand pingCommand = new PingCommand(); + pingCommand.setMessage("ping"); + Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); + Future execFuture = Patterns.ask(pingActor, pingCommand, timeout); + ExecResult execResult = (ExecResult) Await.result(execFuture, timeout.duration()); + if (execResult.getExecResult()) { + logger.info("ping host: {} success", host.getHostname()); + } else { + logger.warn("ping host: {} fail, reason: {}", host.getHostname(), + execResult.getExecOut()); + throw new IllegalStateException("ping host: " + host.getHostname() + " failed."); + } + checkedHost.setHostState(HostState.RUNNING); + checkedHost.setManaged(MANAGED.YES); + } catch (Exception e) { + logger.warn("host: " + host.getHostname() + " rpc error, cause: " + e.getMessage()); + checkedHost.setHostState(HostState.OFFLINE); + } + checkedHosts.add(checkedHost); + } + if (!checkedHosts.isEmpty()) { + clusterHostService.updateBatchById(checkedHosts); + } + } } - try { - String hostname = clusterHostDO.getHostname(); - // 查询内存总量 - String totalMemPromQl = "node_memory_MemTotal_bytes{job=~\"node\",instance=\"" + hostname - + ":9100\"}/1024/1024/1024"; - String totalMemStr = PromInfoUtils.getSinglePrometheusMetric(promUrl, totalMemPromQl); - if (StringUtils.isNotBlank(totalMemStr)) { - int totalMem = Double.valueOf(totalMemStr).intValue(); - clusterHostDO.setTotalMem(totalMem); - } - // 查询内存使用量 - String memAvailablePromQl = "node_memory_MemAvailable_bytes{job=~\"node\",instance=\"" - + hostname + ":9100\"}/1024/1024/1024"; - String memAvailableStr = - PromInfoUtils.getSinglePrometheusMetric(promUrl, memAvailablePromQl); - if (StringUtils.isNotBlank(memAvailableStr)) { - int memAvailable = Double.valueOf(memAvailableStr).intValue(); - Integer memUsed = clusterHostDO.getTotalMem() - memAvailable; - clusterHostDO.setUsedMem(memUsed); - } - // 总磁盘容量 - String totalDistPromQl = "sum(node_filesystem_size_bytes{instance=\"" + hostname - + ":9100\",fstype=~\"ext4|xfs\",mountpoint !~\".*pod.*\"})/1024/1024/1024"; - String totalDiskStr = PromInfoUtils.getSinglePrometheusMetric(promUrl, totalDistPromQl); - if (StringUtils.isNotBlank(totalDiskStr)) { - int totalDisk = Double.valueOf(totalDiskStr).intValue(); - clusterHostDO.setTotalDisk(totalDisk); - } - // 查询磁盘使用量 - String diskUsedPromQl = "sum(node_filesystem_size_bytes{instance=\"" + hostname - + ":9100\",fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}-node_filesystem_free_bytes{instance=\"" - + hostname - + ":9100\",fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"})/1024/1024/1024"; - String diskUsed = PromInfoUtils.getSinglePrometheusMetric(promUrl, diskUsedPromQl); - if (StringUtils.isNotBlank(diskUsed)) { - clusterHostDO.setUsedDisk(Double.valueOf(diskUsed).intValue()); - } - // 查询cpu负载 - String cpuLoadPromQl = "node_load5{job=~\"node\",instance=\"" + hostname + ":9100\"}"; - String cpuLoad = PromInfoUtils.getSinglePrometheusMetric(promUrl, cpuLoadPromQl); - if (StringUtils.isNotBlank(cpuLoad)) { - clusterHostDO.setAverageLoad(cpuLoad); - } - } catch (Exception e) { - logger.warn("check cluster state error, cause: {}", e.getMessage()); - } - } - if (!list.isEmpty()) { - clusterHostService.updateBatchById(list); - } } else { - // 没有 Prometheus?直接获取节点,通过 rpc 检测是否启动 - List hosts = clusterHostService.getHostListByClusterId(clusterInfoEntity.getId()); - List checkedHosts = new ArrayList<>(hosts.size()); - for (ClusterHostDO host : hosts) { - if (hostInfo != null && !StringUtils.equals(host.getHostname(), hostInfo.getHostname())) { - // 指定了节点,直接只处理这一个节点的 - continue; - } - // copy 一个新的,只更新状态 - ClusterHostDO checkedHost = new ClusterHostDO(); - checkedHost.setId(host.getId()); - checkedHost.setCheckTime(new Date()); - try { - // rpc 检测 - final ActorRef pingActor = ActorUtils.getRemoteActor(host.getHostname(), "pingActor"); - PingCommand pingCommand = new PingCommand(); - pingCommand.setMessage("ping"); - Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); - Future execFuture = Patterns.ask(pingActor, pingCommand, timeout); - ExecResult execResult = (ExecResult) Await.result(execFuture, timeout.duration()); - if (execResult.getExecResult()) { - logger.info("ping host: {} success", host.getHostname()); - } else { - logger.warn("ping host: {} fail, reason: {}", host.getHostname(), execResult.getExecOut()); - throw new IllegalStateException("ping host: " + host.getHostname() + " failed."); - } - checkedHost.setHostState(HostState.RUNNING); - checkedHost.setManaged(MANAGED.YES); - } catch (Exception e) { - logger.warn("host: " + host.getHostname() + " rpc error, cause: " + e.getMessage()); - checkedHost.setHostState(HostState.OFFLINE); - } - checkedHosts.add(checkedHost); - } - if (!checkedHosts.isEmpty()) { - clusterHostService.updateBatchById(checkedHosts); - } + unhandled(msg); } - } - } else { - unhandled(msg); } - } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/HostConnectActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/HostConnectActor.java index a876cccf..1f237c30 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/HostConnectActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/HostConnectActor.java @@ -24,8 +24,8 @@ import com.datasophon.common.command.HostCheckCommand; import com.datasophon.common.model.CheckResult; import com.datasophon.common.model.HostInfo; - import com.datasophon.common.utils.HostUtils; + import org.apache.sshd.client.session.ClientSession; import scala.Option; @@ -37,31 +37,31 @@ import cn.hutool.core.util.ObjectUtil; public class HostConnectActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(HostConnectActor.class); - + @Override public void preRestart(Throwable reason, Option message) throws Exception { logger.info("or restart because {}", reason.getMessage()); super.preRestart(reason, message); } - + @Override public void onReceive(Object message) throws Throwable { if (message instanceof HostCheckCommand) { String localIp = HostUtils.getLocalIp(); String localHostName = HostUtils.getLocalHostName(); - logger.info("datasophon manager install hostname and ip :"+localHostName+",",localIp); + logger.info("datasophon manager install hostname and ip :" + localHostName + ",", localIp); HostCheckCommand hostCheckCommand = (HostCheckCommand) message; HostInfo hostInfo = hostCheckCommand.getHostInfo(); logger.info("start host check:{}", hostInfo.getHostname()); - if(hostInfo.getIp().equals(localIp)){ + if (hostInfo.getIp().equals(localIp)) { logger.info("datasophon manager node doesn't need to be checked"); hostInfo.setCheckResult( new CheckResult( Status.CHECK_HOST_SUCCESS.getCode(), Status.CHECK_HOST_SUCCESS.getMsg())); - }else { + } else { ClientSession session = MinaUtils.openConnection( hostInfo.getHostname(), hostInfo.getSshPort(), hostInfo.getSshUser()); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/MasterNodeProcessingActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/MasterNodeProcessingActor.java index 56b1e0a8..e7deb958 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/MasterNodeProcessingActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/MasterNodeProcessingActor.java @@ -1,22 +1,24 @@ package com.datasophon.api.master; -import akka.actor.UntypedActor; -import cn.hutool.json.JSONUtil; import com.datasophon.common.command.OlapSqlExecCommand; import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.OlapUtils; + +import java.util.concurrent.TimeUnit; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.TimeUnit; +import akka.actor.UntypedActor; +import cn.hutool.json.JSONUtil; public class MasterNodeProcessingActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(MasterNodeProcessingActor.class); - + @Override public void onReceive(Object message) throws Throwable { - logger.info("MasterNodeProcessingActor receive message: " + JSONUtil.toJsonStr(message) ); + logger.info("MasterNodeProcessingActor receive message: " + JSONUtil.toJsonStr(message)); if (message instanceof OlapSqlExecCommand) { OlapSqlExecCommand command = (OlapSqlExecCommand) message; ExecResult execResult = new ExecResult(); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/MasterServiceActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/MasterServiceActor.java index 66eacbc2..1ee0f733 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/MasterServiceActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/MasterServiceActor.java @@ -19,7 +19,6 @@ package com.datasophon.api.master; -import akka.actor.UntypedActor; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.master.handler.service.ServiceHandler; import com.datasophon.api.master.handler.service.ServiceStopHandler; @@ -40,34 +39,41 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.NeedRestart; import com.datasophon.dao.enums.ServiceRoleState; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import akka.actor.UntypedActor; public class MasterServiceActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(MasterServiceActor.class); - + @Override public void postStop() { - + logger.info("{} service actor stopped ", getSelf().path().toString()); } - + @Override public void onReceive(Object message) { if (message instanceof ExecuteServiceRoleCommand) { ExecuteServiceRoleCommand executeServiceRoleCommand = (ExecuteServiceRoleCommand) message; - + ClusterServiceRoleGroupConfigService roleGroupConfigService = SpringTool.getApplicationContext() .getBean(ClusterServiceRoleGroupConfigService.class); ClusterServiceRoleInstanceService roleInstanceService = SpringTool.getApplicationContext() .getBean(ClusterServiceRoleInstanceService.class); - + List serviceRoleInfoList = executeServiceRoleCommand.getMasterRoles(); Collections.sort(serviceRoleInfoList); int successNum = 0; @@ -114,7 +120,7 @@ public void onReceive(Object message) { "start to install {} in host {}", serviceRoleInfo.getName(), serviceRoleInfo.getHostname()); - + execResult = ProcessUtils.startInstallService(serviceRoleInfo); if (Objects.nonNull(execResult) && execResult.getExecResult()) { ProcessUtils.saveServiceInstallInfo(serviceRoleInfo); @@ -143,7 +149,7 @@ public void onReceive(Object message) { ServiceExecuteState.ERROR); } } - + } catch (Exception e) { logger.info( "{} install failed in {}", @@ -224,7 +230,7 @@ public void onReceive(Object message) { executeServiceRoleCommand.getClusterId(), ServiceRoleState.STOP); } else { - + if (ServiceRoleType.MASTER.equals(serviceRoleInfo.getRoleType())) { logger.info("{} stop failed", serviceRoleInfo.getParentName()); ProcessUtils.tellCommandActorResult( @@ -296,11 +302,11 @@ public void onReceive(Object message) { unhandled(message); } } - + private boolean isEnableRangerPlugin(Integer clusterId, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); return globalVariables.containsKey("${enable" + serviceName + "Plugin}") && "true".equals(globalVariables.get("${enable" + serviceName + "Plugin}")); } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/PrometheusActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/PrometheusActor.java index 6369d5b7..15a88c0a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/PrometheusActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/PrometheusActor.java @@ -19,17 +19,11 @@ package com.datasophon.api.master; -import akka.actor.ActorSelection; -import akka.actor.UntypedActor; -import akka.pattern.Patterns; -import akka.util.Timeout; -import cn.hutool.http.HttpUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.datasophon.api.load.ServiceRoleJmxMap; import com.datasophon.api.master.handler.service.ServiceConfigureHandler; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterServiceInstanceService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.utils.SpringTool; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; @@ -44,8 +38,7 @@ import com.datasophon.dao.entity.ClusterHostDO; import com.datasophon.dao.entity.ClusterServiceInstanceEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -57,14 +50,25 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; -public class PrometheusActor extends UntypedActor { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(PrometheusActor.class); +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import akka.actor.ActorSelection; +import akka.actor.UntypedActor; +import akka.pattern.Patterns; +import akka.util.Timeout; +import cn.hutool.http.HttpUtil; + +public class PrometheusActor extends UntypedActor { + + private static final Logger logger = LoggerFactory.getLogger(PrometheusActor.class); + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof GeneratePrometheusConfigCommand) { - + GeneratePrometheusConfigCommand command = (GeneratePrometheusConfigCommand) msg; ClusterServiceInstanceService serviceInstanceService = SpringTool.getApplicationContext().getBean(ClusterServiceInstanceService.class); @@ -76,14 +80,14 @@ public void onReceive(Object msg) throws Throwable { List roleInstanceList = roleInstanceService.getServiceRoleInstanceListByServiceId( serviceInstance.getId()); - + ClusterServiceRoleInstanceEntity prometheusInstance = roleInstanceService.getOneServiceRole( "Prometheus", null, command.getClusterId()); - + logger.info("start to genetate {} prometheus config", serviceInstance.getServiceName()); HashMap> configFileMap = new HashMap<>(); - + HashMap> roleMap = new HashMap<>(); for (ClusterServiceRoleInstanceEntity roleInstanceEntity : roleInstanceList) { if (roleMap.containsKey(roleInstanceEntity.getServiceRoleName())) { @@ -159,47 +163,47 @@ public void onReceive(Object msg) throws Throwable { workerGenerators.setOutputDirectory("configs"); workerGenerators.setConfigFormat("custom"); workerGenerators.setTemplateName("scrape.ftl"); - + Generators nodeGenerators = new Generators(); nodeGenerators.setFilename("linux.json"); nodeGenerators.setOutputDirectory("configs"); nodeGenerators.setConfigFormat("custom"); nodeGenerators.setTemplateName("scrape.ftl"); - + Generators masterGenerators = new Generators(); masterGenerators.setFilename("master.json"); masterGenerators.setOutputDirectory("configs"); masterGenerators.setConfigFormat("custom"); masterGenerators.setTemplateName("scrape.ftl"); - + ArrayList workerServiceConfigs = new ArrayList<>(); ArrayList nodeServiceConfigs = new ArrayList<>(); ArrayList masterServiceConfigs = new ArrayList<>(); - + ServiceConfig masterConfig = new ServiceConfig(); masterConfig.setName("master_" + CacheUtils.get(Constants.HOSTNAME)); masterConfig.setValue(CacheUtils.get(Constants.HOSTNAME) + ":8586"); masterConfig.setRequired(true); masterServiceConfigs.add(masterConfig); - + for (ClusterHostDO clusterHostDO : hostList) { ServiceConfig serviceConfig = new ServiceConfig(); serviceConfig.setName("worker_" + clusterHostDO.getHostname()); serviceConfig.setValue(clusterHostDO.getHostname() + ":8585"); serviceConfig.setRequired(true); workerServiceConfigs.add(serviceConfig); - + ServiceConfig nodeServiceConfig = new ServiceConfig(); nodeServiceConfig.setName("node_" + clusterHostDO.getHostname()); nodeServiceConfig.setValue(clusterHostDO.getHostname() + ":9100"); nodeServiceConfig.setRequired(true); nodeServiceConfigs.add(nodeServiceConfig); } - + configFileMap.put(workerGenerators, workerServiceConfigs); configFileMap.put(nodeGenerators, nodeServiceConfigs); - configFileMap.put(masterGenerators,masterServiceConfigs); - + configFileMap.put(masterGenerators, masterServiceConfigs); + ServiceRoleInfo serviceRoleInfo = new ServiceRoleInfo(); serviceRoleInfo.setName("Prometheus"); serviceRoleInfo.setParentName("PROMETHEUS"); @@ -214,9 +218,9 @@ public void onReceive(Object msg) throws Throwable { "http://" + prometheusInstance.getHostname() + ":9090/-/reload", ""); } } - + } else if (msg instanceof GenerateAlertConfigCommand) { - + GenerateAlertConfigCommand command = (GenerateAlertConfigCommand) msg; ClusterServiceRoleInstanceService roleInstanceService = SpringTool.getApplicationContext() @@ -241,7 +245,7 @@ public void onReceive(Object msg) throws Throwable { "http://" + prometheusInstance.getHostname() + ":9090/-/reload", ""); } } - + } else if (msg instanceof GenerateSRPromConfigCommand) { GenerateSRPromConfigCommand command = (GenerateSRPromConfigCommand) msg; ClusterServiceInstanceService serviceInstanceService = @@ -254,17 +258,17 @@ public void onReceive(Object msg) throws Throwable { List roleInstanceList = roleInstanceService.getServiceRoleInstanceListByServiceId( serviceInstance.getId()); - + ClusterServiceRoleInstanceEntity prometheusInstance = roleInstanceService.getOneServiceRole( "Prometheus", null, command.getClusterId()); - + logger.info("start to genetate {} prometheus config", serviceInstance.getServiceName()); HashMap> configFileMap = new HashMap<>(); - + ArrayList feList = new ArrayList<>(); ArrayList beList = new ArrayList<>(); - + for (ClusterServiceRoleInstanceEntity roleInstanceEntity : roleInstanceList) { String jmxKey = command.getClusterFrame() @@ -290,13 +294,13 @@ public void onReceive(Object msg) throws Throwable { generators.setOutputDirectory("configs"); generators.setConfigFormat("custom"); generators.setTemplateName("starrocks-prom.ftl"); - + ServiceConfig feServiceConfig = new ServiceConfig(); feServiceConfig.setName("feList"); feServiceConfig.setValue(feList); feServiceConfig.setRequired(true); feServiceConfig.setConfigType("map"); - + ServiceConfig beServiceConfig = new ServiceConfig(); beServiceConfig.setName("beList"); beServiceConfig.setValue(beList); @@ -305,7 +309,7 @@ public void onReceive(Object msg) throws Throwable { serviceConfigs.add(feServiceConfig); serviceConfigs.add(beServiceConfig); configFileMap.put(generators, serviceConfigs); - + ServiceRoleInfo serviceRoleInfo = new ServiceRoleInfo(); serviceRoleInfo.setName("Prometheus"); serviceRoleInfo.setParentName("PROMETHEUS"); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/RackActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/RackActor.java index c70ebbda..9aa28473 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/RackActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/RackActor.java @@ -18,9 +18,9 @@ package com.datasophon.api.master; import com.datasophon.api.master.handler.service.ServiceConfigureHandler; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.utils.PackageUtils; import com.datasophon.api.utils.ProcessUtils; import com.datasophon.api.utils.SpringTool; @@ -45,14 +45,14 @@ import akka.actor.UntypedActor; public class RackActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(RackActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof GenerateRackPropCommand) { GenerateRackPropCommand command = (GenerateRackPropCommand) msg; - + ClusterServiceRoleInstanceService roleInstanceService = SpringTool.getApplicationContext().getBean(ClusterServiceRoleInstanceService.class); ClusterHostService hostService = SpringTool.getApplicationContext().getBean(ClusterHostService.class); @@ -68,7 +68,7 @@ public void onReceive(Object msg) throws Throwable { generators.setFilename("rack.properties"); generators.setOutputDirectory("etc/hadoop"); generators.setConfigFormat("properties2"); - + ArrayList serviceConfigs = new ArrayList<>(); List hostList = hostService.list(); for (ClusterHostDO clusterHostDO : hostList) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/RemoteEventActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/RemoteEventActor.java index 8d206d64..ceb16a6d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/RemoteEventActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/RemoteEventActor.java @@ -26,9 +26,9 @@ import akka.remote.DisassociatedEvent; public class RemoteEventActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(RemoteEventActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof AssociationErrorEvent) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/ServiceCommandActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/ServiceCommandActor.java index 8de9f095..97e88cd4 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/ServiceCommandActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/ServiceCommandActor.java @@ -17,9 +17,6 @@ package com.datasophon.api.master; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.service.ClusterAlertQuotaService; import com.datasophon.api.service.ClusterInfoService; @@ -41,9 +38,9 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceWebuis; import com.datasophon.dao.enums.ClusterState; import com.datasophon.dao.enums.CommandState; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; + import scala.Option; import java.util.Date; @@ -51,39 +48,47 @@ import java.util.Map; import java.util.stream.Collectors; -public class ServiceCommandActor extends UntypedActor { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(ServiceCommandActor.class); +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; - private static final String STARROCKS = "starrocks"; +import akka.actor.ActorRef; +import akka.actor.UntypedActor; +public class ServiceCommandActor extends UntypedActor { + + private static final Logger logger = LoggerFactory.getLogger(ServiceCommandActor.class); + + private static final String STARROCKS = "starrocks"; + private static final String DORIS = "doris"; - + private static final String HDFS = "hdfs"; - + private static final String ENABLE_HDFS_KERBEROS = "${enableHDFSKerberos}"; - + private static final String TRUE = "true"; - + private static final String FALSE = "false"; - + private static final String HTTP = "http"; - + private static final String HTTPS = "https"; - + private static final String NODE = "NODE"; - + @Override public void preRestart(Throwable reason, Option message) throws Exception { logger.info("service command actor restart because {}", reason.getMessage()); super.preRestart(reason, message); } - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof UpdateCommandHostMessage) { UpdateCommandHostMessage message = (UpdateCommandHostMessage) msg; - + ClusterInfoService clusterInfoService = SpringTool.getApplicationContext().getBean(ClusterInfoService.class); ClusterServiceCommandHostCommandService service = @@ -92,7 +97,7 @@ public void onReceive(Object msg) throws Throwable { SpringTool.getApplicationContext().getBean(ClusterServiceCommandHostService.class); ClusterServiceCommandService commandService = SpringTool.getApplicationContext().getBean(ClusterServiceCommandService.class); - + ClusterServiceCommandHostEntity commandHost = commandHostService.getOne(new QueryWrapper() .eq(Constants.COMMAND_HOST_ID, message.getCommandHostId())); @@ -102,7 +107,7 @@ public void onReceive(Object msg) throws Throwable { message.getCommandHostId()); int progress = totalProgress / size; commandHost.setCommandProgress(progress); - + if (progress == 100) { List list = service.findFailedHostCommand(message.getHostname(), message.getCommandHostId()); @@ -128,30 +133,30 @@ public void onReceive(Object msg) throws Throwable { if (progress1 == 100) { command.setCommandState(CommandState.SUCCESS); command.setEndTime(new Date()); - + String serviceName = command.getServiceName(); ClusterInfoEntity clusterInfo = clusterInfoService.getById(command.getClusterId()); - + if (command.getCommandType() == 4 && HDFS.equalsIgnoreCase(serviceName)) { - //update web ui + // update web ui updateHDFSWebUi(clusterInfo.getId(), command.getServiceInstanceId()); } - + // update cluster state if (command.getCommandType() == 1) { - + if (ClusterState.NEED_CONFIG.equals(clusterInfo.getClusterState())) { clusterInfo.setClusterState(ClusterState.RUNNING); clusterInfoService.updateById(clusterInfo); } - + if (HDFS.equalsIgnoreCase(serviceName)) { ActorRef hdfsECActor = ActorUtils.getLocalActor(HdfsECActor.class, ActorUtils.getActorRefName(HdfsECActor.class)); HdfsEcCommand hdfsEcCommand = new HdfsEcCommand(); hdfsEcCommand.setServiceInstanceId(command.getServiceInstanceId()); hdfsECActor.tell(hdfsEcCommand, getSelf()); - + } logger.info("start to generate prometheus config"); ActorRef prometheusActor = ActorUtils.getLocalActor(PrometheusActor.class, @@ -179,7 +184,7 @@ public void onReceive(Object msg) throws Throwable { command.setCommandState(CommandState.FAILED); command.setEndTime(new Date()); } - + List cancelList = commandHostService.findCanceledCommandHost(message.getCommandId()); if (!cancelList.isEmpty()) { @@ -191,7 +196,7 @@ public void onReceive(Object msg) throws Throwable { .update(command); } } - + private void enableAlertConfig(String serviceName, Integer clusterId) { ClusterAlertQuotaService alertQuotaService = SpringTool.getApplicationContext().getBean(ClusterAlertQuotaService.class); @@ -200,13 +205,14 @@ private void enableAlertConfig(String serviceName, Integer clusterId) { String alertQuotaIds = StringUtils.join(ids, ","); alertQuotaService.start(clusterId, alertQuotaIds); } - + private void updateHDFSWebUi(Integer clusterId, Integer serviceInstanceId) { Map variables = GlobalVariables.get(clusterId); if (variables.containsKey(ENABLE_HDFS_KERBEROS)) { ClusterServiceRoleInstanceWebuisService webuisService = SpringTool.getApplicationContext().getBean(ClusterServiceRoleInstanceWebuisService.class); - List webUis = webuisService.listWebUisByServiceInstanceId(serviceInstanceId); + List webUis = + webuisService.listWebUisByServiceInstanceId(serviceInstanceId); for (ClusterServiceRoleInstanceWebuis webUi : webUis) { if (TRUE.equals(variables.get(ENABLE_HDFS_KERBEROS)) && webUi.getWebUrl().contains("9870")) { String newWebUi = webUi.getWebUrl().replace(HTTP, HTTPS).replace("9870", "9871"); @@ -221,5 +227,5 @@ private void updateHDFSWebUi(Integer clusterId, Integer serviceInstanceId) { } } } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/ServiceExecuteResultActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/ServiceExecuteResultActor.java index 9a705e1a..3ac2eb78 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/ServiceExecuteResultActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/ServiceExecuteResultActor.java @@ -38,14 +38,14 @@ import akka.actor.UntypedActor; public class ServiceExecuteResultActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(ServiceExecuteResultActor.class); - + @Override public void onReceive(Object message) throws Throwable { if (message instanceof ServiceExecuteResultMessage) { ServiceExecuteResultMessage result = (ServiceExecuteResultMessage) message; - + DAGGraph dag = result.getDag(); Map activeTaskList = result.getActiveTaskList(); Map errorTaskList = result.getErrorTaskList(); @@ -93,7 +93,7 @@ public void onReceive(Object message) throws Throwable { serviceActor, ServiceRoleType.WORKER); } - + } else { activeTaskList.remove(node); readyToSubmitTaskList.remove(node); @@ -107,7 +107,7 @@ public void onReceive(Object message) throws Throwable { unhandled(message); } } - + public void listCancelCommand(DAGGraph dag, String node, List commandIds) { if (dag.getSubsequentNodes(node).size() == 0) { return; @@ -118,7 +118,7 @@ public void listCancelCommand(DAGGraph dag, String listCancelCommand(dag, subsequentNode, commandIds); } } - + private void tellToSubmitActiveTaskNode(ServiceExecuteResultMessage result, DAGGraph dag, Map activeTaskList, @@ -140,10 +140,10 @@ private void tellToSubmitActiveTaskNode(ServiceExecuteResultMessage result, submitActiveTaskNodeCommand.setErrorTaskList(errorTaskList); submitActiveTaskNodeCommand.setReadyToSubmitTaskList(readyToSubmitTaskList); submitActiveTaskNodeCommand.setCompleteTaskList(completeTaskList); - + submitActiveTaskNodeCommand.setClusterCode(result.getClusterCode()); - + submitTaskNodeActor.tell(submitActiveTaskNodeCommand, getSelf()); } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/SubmitTaskNodeActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/SubmitTaskNodeActor.java index 955d4b82..e5248ae3 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/SubmitTaskNodeActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/SubmitTaskNodeActor.java @@ -38,18 +38,18 @@ import akka.actor.UntypedActor; public class SubmitTaskNodeActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(SubmitTaskNodeActor.class); - + @Override public void preRestart(Throwable reason, Option message) throws Exception { logger.info("service command actor restart because {}", reason.getMessage()); super.preRestart(reason, message); } - + @Override public void onReceive(Object message) throws Throwable { - + if (message instanceof SubmitActiveTaskNodeCommand) { SubmitActiveTaskNodeCommand submitActiveTaskNodeCommand = (SubmitActiveTaskNodeCommand) message; DAGGraph dag = submitActiveTaskNodeCommand.getDag(); @@ -77,9 +77,9 @@ public void onReceive(Object message) throws Throwable { } ServiceNode serviceNode = dag.getNode(node); List masterRoles = serviceNode.getMasterRoles(); - + activeTaskList.put(node, ServiceExecuteState.RUNNING); - + if (!masterRoles.isEmpty()) { logger.info("start to submit {} master roles", node); ActorRef serviceActor = ActorUtils.getLocalActor(MasterServiceActor.class, @@ -98,7 +98,7 @@ public void onReceive(Object message) throws Throwable { null, serviceActor, ServiceRoleType.MASTER); - + } else if (!serviceNode.getElseRoles().isEmpty()) { logger.info("{} does not has master roles , start to submit worker or client roles", node); for (ServiceRoleInfo elseRole : serviceNode.getElseRoles()) { @@ -120,11 +120,11 @@ public void onReceive(Object message) throws Throwable { serviceActor, ServiceRoleType.WORKER); } - + } } } } } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/WorkerServiceActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/WorkerServiceActor.java index 63671de2..fa040583 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/WorkerServiceActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/WorkerServiceActor.java @@ -17,7 +17,6 @@ package com.datasophon.api.master; -import akka.actor.UntypedActor; import com.datasophon.api.master.handler.service.ServiceHandler; import com.datasophon.api.master.handler.service.ServiceStopHandler; import com.datasophon.api.service.ClusterServiceRoleGroupConfigService; @@ -35,28 +34,31 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.NeedRestart; import com.datasophon.dao.enums.ServiceRoleState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -public class WorkerServiceActor extends UntypedActor { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(WorkerServiceActor.class); +import akka.actor.UntypedActor; +public class WorkerServiceActor extends UntypedActor { + + private static final Logger logger = LoggerFactory.getLogger(WorkerServiceActor.class); + @Override public void onReceive(Object message) throws Throwable { if (message instanceof ExecuteServiceRoleCommand) { ExecuteServiceRoleCommand executeServiceRoleCommand = (ExecuteServiceRoleCommand) message; - + ClusterServiceRoleGroupConfigService roleGroupConfigService = SpringTool.getApplicationContext().getBean(ClusterServiceRoleGroupConfigService.class); ClusterServiceRoleInstanceService roleInstanceService = SpringTool.getApplicationContext().getBean(ClusterServiceRoleInstanceService.class); - + ServiceRoleInfo serviceRoleInfo = executeServiceRoleCommand.getWorkerRole(); ExecResult execResult = new ExecResult(); Integer serviceInstanceId = serviceRoleInfo.getServiceInstanceId(); @@ -152,5 +154,5 @@ public void onReceive(Object message) throws Throwable { unhandled(message); } } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/WorkerStartActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/WorkerStartActor.java index 1a11a8e4..a832d8ec 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/WorkerStartActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/WorkerStartActor.java @@ -17,9 +17,10 @@ package com.datasophon.api.master; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import cn.hutool.core.util.ObjectUtil; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.toList; + import com.datasophon.api.service.ClusterGroupService; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterServiceCommandService; @@ -43,24 +44,25 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.entity.ClusterUser; +import com.datasophon.dao.enums.ServiceRoleState; import com.datasophon.domain.host.enums.MANAGED; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.datasophon.dao.enums.ServiceRoleState; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import static java.util.stream.Collectors.groupingBy; -import static java.util.stream.Collectors.mapping; -import static java.util.stream.Collectors.toList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class WorkerStartActor extends UntypedActor { +import akka.actor.ActorRef; +import akka.actor.UntypedActor; +import cn.hutool.core.util.ObjectUtil; +public class WorkerStartActor extends UntypedActor { + private static final Logger logger = LoggerFactory.getLogger(WorkerStartActor.class); - + @Override public void onReceive(Object message) throws Throwable { if (message instanceof StartWorkerMessage) { @@ -68,12 +70,12 @@ public void onReceive(Object message) throws Throwable { String hostname = msg.getHostname(); Integer clusterId = msg.getClusterId(); logger.info("Receive message when worker first start :{}", hostname); - + ClusterHostService clusterHostService = SpringTool.getApplicationContext().getBean(ClusterHostService.class); ClusterInfoService clusterInfoService = SpringTool.getApplicationContext().getBean(ClusterInfoService.class); - + // is managed? ClusterHostDO hostEntity = clusterHostService.getClusterHostByHostname(hostname); ClusterInfoEntity cluster = clusterInfoService.getById(clusterId); @@ -100,59 +102,60 @@ public void onReceive(Object message) throws Throwable { hostEntity.setManaged(MANAGED.YES); clusterHostService.updateById(hostEntity); } - + // add to prometheus ActorRef prometheusActor = ActorUtils.getLocalActor(PrometheusActor.class, ActorUtils.getActorRefName(PrometheusActor.class)); GenerateHostPrometheusConfig prometheusConfigCommand = new GenerateHostPrometheusConfig(); prometheusConfigCommand.setClusterId(cluster.getId()); prometheusActor.tell(prometheusConfigCommand, getSelf()); - + // tell to worker what need to start - autoAddServiceOperatorNeeded(msg.getHostname(), cluster.getId(), CommandType.START_SERVICE,false); - } else if(message instanceof WorkerServiceMessage) { + autoAddServiceOperatorNeeded(msg.getHostname(), cluster.getId(), CommandType.START_SERVICE, false); + } else if (message instanceof WorkerServiceMessage) { WorkerServiceMessage msg = (WorkerServiceMessage) message; // tell to worker what need to start/stop - autoAddServiceOperatorNeeded(msg.getHostname(), msg.getClusterId(), msg.getCommandType(),true); + autoAddServiceOperatorNeeded(msg.getHostname(), msg.getClusterId(), msg.getCommandType(), true); } } - + /** * Automatically start/stop services that need to be started * * @param clusterId */ - private void autoAddServiceOperatorNeeded(String hostname, Integer clusterId,CommandType commandType, - boolean needRestart) { + private void autoAddServiceOperatorNeeded(String hostname, Integer clusterId, CommandType commandType, + boolean needRestart) { ClusterServiceRoleInstanceService roleInstanceService = SpringTool.getApplicationContext().getBean(ClusterServiceRoleInstanceService.class); ClusterServiceCommandService serviceCommandService = SpringTool.getApplicationContext().getBean(ClusterServiceCommandService.class); - + List serviceRoleList = null; // 启动服务 if (CommandType.START_SERVICE.equals(commandType)) { serviceRoleList = roleInstanceService - .listStoppedServiceRoleListByHostnameAndClusterId(hostname, clusterId); + .listStoppedServiceRoleListByHostnameAndClusterId(hostname, clusterId); // 重启时重刷服务配置以支持磁盘故障等问题 - if(needRestart){ + if (needRestart) { roleInstanceService.updateToNeedRestartByHost(hostname); } } - + // 停止运行状态的服务 - if(commandType.STOP_SERVICE.equals(commandType)){ + if (commandType.STOP_SERVICE.equals(commandType)) { serviceRoleList = roleInstanceService - .getServiceRoleListByHostnameAndClusterId(hostname, clusterId).stream() - .filter(roleInstance -> (!ServiceRoleState.STOP.equals(roleInstance.getServiceRoleState()) && - !ServiceRoleState.DECOMMISSIONED.equals(roleInstance.getServiceRoleState()))).collect(toList()); + .getServiceRoleListByHostnameAndClusterId(hostname, clusterId).stream() + .filter(roleInstance -> (!ServiceRoleState.STOP.equals(roleInstance.getServiceRoleState()) && + !ServiceRoleState.DECOMMISSIONED.equals(roleInstance.getServiceRoleState()))) + .collect(toList()); } - + if (CollectionUtils.isEmpty(serviceRoleList)) { logger.info("No services need to start at host {}.", hostname); return; } - + Map> serviceRoleMap = serviceRoleList.stream() .collect( groupingBy( @@ -166,11 +169,11 @@ private void autoAddServiceOperatorNeeded(String hostname, Integer clusterId,Com logger.info("Some service auto-start failed, please check logs of the services that failed to start."); } } - + private void syncClusterUserAndGroup(Integer clusterId, String hostname) { ClusterGroupService clusterGroupService = SpringTool.getApplicationContext().getBean(ClusterGroupService.class); ClusterUserService clusterUserService = SpringTool.getApplicationContext().getBean(ClusterUserService.class); - + List userGroupList = clusterGroupService.listAllUserGroup(clusterId); for (ClusterGroup clusterGroup : userGroupList) { String groupName = clusterGroup.getGroupName(); @@ -181,5 +184,5 @@ private void syncClusterUserAndGroup(Integer clusterId, String hostname) { clusterUserService.createUnixUserOnHost(clusterUser, hostname); } } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/alert/AlertActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/alert/AlertActor.java index daaf348b..dd67b9b2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/alert/AlertActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/alert/AlertActor.java @@ -1,18 +1,14 @@ package com.datasophon.api.master.alert; -import akka.actor.UntypedActor; -import cn.hutool.extra.spring.SpringUtil; -import com.alibaba.fastjson.JSONObject; import com.datasophon.api.service.ClusterAlertHistoryService; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterServiceInstanceService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.dao.entity.ClusterAlertHistory; import com.datasophon.dao.entity.ClusterHostDO; import com.datasophon.dao.entity.ClusterServiceInstanceEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; -import com.datasophon.domain.host.enums.HostState; import com.datasophon.dao.enums.ServiceRoleState; import com.datasophon.dao.enums.ServiceState; import com.datasophon.domain.alert.gateway.AlertHistoryGateway; @@ -20,23 +16,29 @@ import com.datasophon.domain.alert.model.AlertLabels; import com.datasophon.domain.alert.model.AlertMessage; import com.datasophon.domain.alert.model.Alerts; +import com.datasophon.domain.host.enums.HostState; import java.util.Date; import java.util.List; import java.util.Objects; -public class AlertActor extends UntypedActor { +import com.alibaba.fastjson.JSONObject; - private static final String FIRING = "firing"; +import akka.actor.UntypedActor; +import cn.hutool.extra.spring.SpringUtil; +public class AlertActor extends UntypedActor { + + private static final String FIRING = "firing"; + private static final String NODE = "node"; - + private static final String WARNING = "warning"; - + private static final String EXCEPTION = "exception"; - + private static final String RESOLVED = "resolved"; - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof String) { @@ -45,9 +47,11 @@ public void onReceive(Object msg) throws Throwable { AlertHistoryGateway alertHistoryGateway = SpringUtil.getBean(AlertHistoryGateway.class); ClusterHostService hostService = SpringUtil.getBean(ClusterHostService.class); ClusterAlertHistoryService alertHistoryService = SpringUtil.getBean(ClusterAlertHistoryService.class); - ClusterServiceInstanceService serviceInstanceService = SpringUtil.getBean(ClusterServiceInstanceService.class); - ClusterServiceRoleInstanceService roleInstanceService = SpringUtil.getBean(ClusterServiceRoleInstanceService.class); - + ClusterServiceInstanceService serviceInstanceService = + SpringUtil.getBean(ClusterServiceInstanceService.class); + ClusterServiceRoleInstanceService roleInstanceService = + SpringUtil.getBean(ClusterServiceRoleInstanceService.class); + List alerts = alertMes.getAlerts(); for (Alerts alertInfo : alerts) { AlertLabels labels = alertInfo.getLabels(); @@ -58,11 +62,13 @@ public void onReceive(Object msg) throws Throwable { String hostname = instance.split(":")[0]; String serviceRoleName = labels.getServiceRoleName(); if (FIRING.equals(status)) { - Boolean hasEnabledAlertHistory = alertHistoryGateway.hasEnabledAlertHistory(alertname, clusterId, hostname); + Boolean hasEnabledAlertHistory = + alertHistoryGateway.hasEnabledAlertHistory(alertname, clusterId, hostname); // 查询服务实例,服务角色实例 if (NODE.equals(serviceRoleName)) { ClusterHostDO clusterHost = hostService.getClusterHostByHostname(hostname); - clusterHost.setHostState(EXCEPTION.equals(labels.getSeverity()) ? HostState.OFFLINE : HostState.EXISTS_ALARM); + clusterHost.setHostState( + EXCEPTION.equals(labels.getSeverity()) ? HostState.OFFLINE : HostState.EXISTS_ALARM); if (!hasEnabledAlertHistory) { ClusterAlertHistory clusterAlertHistory = ClusterAlertHistory.builder() .clusterId(clusterId) @@ -70,7 +76,8 @@ public void onReceive(Object msg) throws Throwable { .alertTargetName(alertname) .createTime(new Date()) .updateTime(new Date()) - .alertLevel(WARNING.equals(labels.getSeverity()) ? AlertLevel.WARN : AlertLevel.EXCEPTION) + .alertLevel(WARNING.equals(labels.getSeverity()) ? AlertLevel.WARN + : AlertLevel.EXCEPTION) .alertInfo(alertInfo.getAnnotations().getDescription()) .alertAdvice(alertInfo.getAnnotations().getSummary()) .hostname(hostname) @@ -80,9 +87,11 @@ public void onReceive(Object msg) throws Throwable { } hostService.updateById(clusterHost); } else { - ClusterServiceRoleInstanceEntity roleInstance = roleInstanceService.getOneServiceRole(serviceRoleName, hostname, clusterId); + ClusterServiceRoleInstanceEntity roleInstance = + roleInstanceService.getOneServiceRole(serviceRoleName, hostname, clusterId); if (Objects.nonNull(roleInstance)) { - ClusterServiceInstanceEntity serviceInstance = serviceInstanceService.getById(roleInstance.getServiceId()); + ClusterServiceInstanceEntity serviceInstance = + serviceInstanceService.getById(roleInstance.getServiceId()); serviceInstance.setServiceState(ServiceState.EXISTS_ALARM); roleInstance.setServiceRoleState(ServiceRoleState.EXISTS_ALARM); if (!hasEnabledAlertHistory) { @@ -94,13 +103,14 @@ public void onReceive(Object msg) throws Throwable { .serviceRoleInstanceId(roleInstance.getId()) .createTime(new Date()) .updateTime(new Date()) - .alertLevel(WARNING.equals(labels.getSeverity()) ? AlertLevel.WARN : AlertLevel.EXCEPTION) + .alertLevel(WARNING.equals(labels.getSeverity()) ? AlertLevel.WARN + : AlertLevel.EXCEPTION) .alertInfo(alertInfo.getAnnotations().getDescription()) .alertAdvice(alertInfo.getAnnotations().getSummary()) .hostname(hostname) .isEnabled(1) .build(); - + alertHistoryService.save(clusterAlertHistory); } if (EXCEPTION.equals(labels.getSeverity())) { @@ -111,22 +121,26 @@ public void onReceive(Object msg) throws Throwable { roleInstanceService.updateById(roleInstance); } } - + } if (RESOLVED.equals(status)) { - AlertHistory alertHistory = alertHistoryGateway.getEnabledAlertHistory(alertname, clusterId, hostname); - if(Objects.nonNull(alertHistory)){ - boolean nodeHasWarnAlertList = alertHistoryGateway.nodeHasWarnAlertList(hostname, serviceRoleName, alertHistory.getId()); - + AlertHistory alertHistory = + alertHistoryGateway.getEnabledAlertHistory(alertname, clusterId, hostname); + if (Objects.nonNull(alertHistory)) { + boolean nodeHasWarnAlertList = alertHistoryGateway.nodeHasWarnAlertList(hostname, + serviceRoleName, alertHistory.getId()); + if (EXCEPTION.equals(labels.getSeverity())) {// 异常告警处理 if (NODE.equals(serviceRoleName)) { // 置为正常 ClusterHostDO clusterHost = hostService.getClusterHostByHostname(hostname); - clusterHost.setHostState(nodeHasWarnAlertList ? HostState.EXISTS_ALARM : HostState.RUNNING); + clusterHost.setHostState( + nodeHasWarnAlertList ? HostState.EXISTS_ALARM : HostState.RUNNING); hostService.updateById(clusterHost); } else { // 查询服务角色实例 - ClusterServiceRoleInstanceEntity roleInstance = roleInstanceService.getOneServiceRole(labels.getServiceRoleName(), hostname, clusterId); + ClusterServiceRoleInstanceEntity roleInstance = roleInstanceService + .getOneServiceRole(labels.getServiceRoleName(), hostname, clusterId); if (roleInstance.getServiceRoleState() != ServiceRoleState.RUNNING) { roleInstance.setServiceRoleState(ServiceRoleState.RUNNING); if (nodeHasWarnAlertList) { @@ -140,11 +154,13 @@ public void onReceive(Object msg) throws Throwable { if (NODE.equals(serviceRoleName)) { // 置为正常 ClusterHostDO clusterHost = hostService.getClusterHostByHostname(hostname); - clusterHost.setHostState(nodeHasWarnAlertList ? HostState.EXISTS_ALARM : HostState.RUNNING); + clusterHost.setHostState( + nodeHasWarnAlertList ? HostState.EXISTS_ALARM : HostState.RUNNING); hostService.updateById(clusterHost); } else { // 查询服务角色实例 - ClusterServiceRoleInstanceEntity roleInstance = roleInstanceService.getOneServiceRole(labels.getServiceRoleName(), hostname, clusterId); + ClusterServiceRoleInstanceEntity roleInstance = roleInstanceService + .getOneServiceRole(labels.getServiceRoleName(), hostname, clusterId); if (roleInstance.getServiceRoleState() != ServiceRoleState.RUNNING) { if (nodeHasWarnAlertList) { roleInstance.setServiceRoleState(ServiceRoleState.EXISTS_ALARM); @@ -164,5 +180,3 @@ public void onReceive(Object msg) throws Throwable { } } } - - diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/alert/ServiceRoleCheckActor.java b/datasophon-service/src/main/java/com/datasophon/api/master/alert/ServiceRoleCheckActor.java index c62a3d39..27c23a46 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/alert/ServiceRoleCheckActor.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/alert/ServiceRoleCheckActor.java @@ -19,8 +19,6 @@ package com.datasophon.api.master.alert; -import akka.actor.UntypedActor; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.datasophon.api.service.ClusterServiceRoleInstanceService; import com.datasophon.api.strategy.ServiceRoleStrategy; import com.datasophon.api.strategy.ServiceRoleStrategyContext; @@ -34,15 +32,19 @@ import java.util.Objects; import java.util.stream.Collectors; -public class ServiceRoleCheckActor extends UntypedActor { +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +import akka.actor.UntypedActor; +public class ServiceRoleCheckActor extends UntypedActor { + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ServiceRoleCheckCommand) { ClusterServiceRoleInstanceService roleInstanceService = SpringTool.getApplicationContext() .getBean(ClusterServiceRoleInstanceService.class); - + List list = roleInstanceService.list( new QueryWrapper() @@ -59,9 +61,8 @@ public void onReceive(Object msg) throws Throwable { "DorisBE", "NameNode", "ResourceManager", - "ElasticSearch" - )); - + "ElasticSearch")); + if (!list.isEmpty()) { Map map = translateListToMap(list); for (ClusterServiceRoleInstanceEntity roleInstanceEntity : list) { @@ -77,7 +78,7 @@ public void onReceive(Object msg) throws Throwable { } } } - + private Map translateListToMap( List list) { return list.stream() diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/CheckWorkerMd5Handler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/CheckWorkerMd5Handler.java index 22f283ca..c72888e2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/CheckWorkerMd5Handler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/CheckWorkerMd5Handler.java @@ -34,7 +34,7 @@ import cn.hutool.core.io.FileUtil; public class CheckWorkerMd5Handler implements DispatcherWorkerHandler { - + private static final Logger logger = LoggerFactory.getLogger(CheckWorkerMd5Handler.class); @Override public boolean handle(ClientSession session, HostInfo hostInfo) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DecompressWorkerHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DecompressWorkerHandler.java index 72e184a4..6dcf4d3d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DecompressWorkerHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DecompressWorkerHandler.java @@ -30,9 +30,9 @@ import org.slf4j.LoggerFactory; public class DecompressWorkerHandler implements DispatcherWorkerHandler { - + private static final Logger logger = LoggerFactory.getLogger(DecompressWorkerHandler.class); - + @Override public boolean handle(ClientSession session, HostInfo hostInfo) { String decompressResult = MinaUtils.execCmdWithResult(session, Constants.UNZIP_DDH_WORKER_CMD); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandler.java index 18096fd1..e16c998b 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandler.java @@ -24,6 +24,6 @@ import java.net.UnknownHostException; public interface DispatcherWorkerHandler { - + boolean handle(ClientSession session, HostInfo hostInfo) throws UnknownHostException; } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandlerChain.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandlerChain.java index 9fac7de6..ee3fc13d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandlerChain.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/DispatcherWorkerHandlerChain.java @@ -26,13 +26,13 @@ import java.util.List; public class DispatcherWorkerHandlerChain { - + private List handlers = new ArrayList<>(); - + public void addHandler(DispatcherWorkerHandler handler) { this.handlers.add(handler); } - + public void handle(ClientSession session, HostInfo hostInfo) throws UnknownHostException { for (DispatcherWorkerHandler handler : handlers) { boolean handled = handler.handle(session, hostInfo); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/InstallJDKHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/InstallJDKHandler.java index 865ff63d..c481c42e 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/InstallJDKHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/InstallJDKHandler.java @@ -22,16 +22,16 @@ import com.datasophon.common.Constants; import com.datasophon.common.model.HostInfo; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.sshd.client.session.ClientSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class InstallJDKHandler implements DispatcherWorkerHandler { - + private static final Logger logger = LoggerFactory.getLogger(InstallJDKHandler.class); - + @Override public boolean handle(ClientSession session, HostInfo hostInfo) { hostInfo.setProgress(60); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/StartWorkerHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/StartWorkerHandler.java index bd7d0522..fbdc41fc 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/StartWorkerHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/StartWorkerHandler.java @@ -25,28 +25,30 @@ import com.datasophon.common.Constants; import com.datasophon.common.enums.InstallState; import com.datasophon.common.model.HostInfo; -import org.apache.commons.lang.StringUtils; + +import org.apache.commons.lang3.StringUtils; import org.apache.sshd.client.session.ClientSession; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Date; -public class StartWorkerHandler implements DispatcherWorkerHandler { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +public class StartWorkerHandler implements DispatcherWorkerHandler { + private static final Logger logger = LoggerFactory.getLogger(StartWorkerHandler.class); - + private Integer clusterId; - + private String clusterFrame; - + public StartWorkerHandler(Integer clusterId, String clusterFrame) { this.clusterId = clusterId; this.clusterFrame = clusterFrame; } - + @Override public boolean handle(ClientSession session, HostInfo hostInfo) throws UnknownHostException { ConfigBean configBean = SpringTool.getApplicationContext().getBean(ConfigBean.class); @@ -69,10 +71,10 @@ public boolean handle(ClientSession session, HostInfo hostInfo) throws UnknownHo hostInfo.setMessage(MessageResolverUtils.getMessage("modify.configuration.file.fail")); CommonUtils.updateInstallState(InstallState.FAILED, hostInfo); } else { - //Initialize environment + // Initialize environment MinaUtils.execCmdWithResult(session, "ulimit -n 102400"); MinaUtils.execCmdWithResult(session, "sysctl -w vm.max_map_count=2000000"); - //Set startup and self start + // Set startup and self start MinaUtils.execCmdWithResult(session, "\\cp " + installPath + "/datasophon-worker/script/datasophon-worker /etc/rc.d/init.d/"); MinaUtils.execCmdWithResult(session, "chmod +x /etc/rc.d/init.d/datasophon-worker"); @@ -85,7 +87,7 @@ public boolean handle(ClientSession session, HostInfo hostInfo) throws UnknownHo hostInfo.setProgress(75); hostInfo.setCreateTime(new Date()); } - + logger.info("end dispatcher host agent :{}", hostInfo.getHostname()); return true; } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/UploadWorkerHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/UploadWorkerHandler.java index 5e6c6a10..f821b009 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/UploadWorkerHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/host/UploadWorkerHandler.java @@ -30,9 +30,9 @@ import org.slf4j.LoggerFactory; public class UploadWorkerHandler implements DispatcherWorkerHandler { - + private static final Logger logger = LoggerFactory.getLogger(StartWorkerHandler.class); - + @Override public boolean handle(ClientSession session, HostInfo hostInfo) { boolean uploadFile = MinaUtils.uploadFile(session, diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureAsyncHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureAsyncHandler.java index 25e7e297..d2b85ce2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureAsyncHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureAsyncHandler.java @@ -17,60 +17,64 @@ package com.datasophon.api.master.handler.service; -import akka.actor.ActorSelection; -import akka.dispatch.OnComplete; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.master.ActorUtils; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.GenerateServiceConfigCommand; import com.datasophon.common.model.ServiceRoleInfo; import com.datasophon.common.utils.ExecResult; -import java.util.Objects; -import java.util.concurrent.TimeUnit; + import scala.concurrent.Future; import scala.concurrent.duration.Duration; -public class ServiceConfigureAsyncHandler extends ServiceHandler { - - private final OnComplete function; +import java.util.Objects; +import java.util.concurrent.TimeUnit; - public ServiceConfigureAsyncHandler(OnComplete function) { - this.function = function; - } +import akka.actor.ActorSelection; +import akka.dispatch.OnComplete; +import akka.pattern.Patterns; +import akka.util.Timeout; - @Override - public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) { - ExecResult execResult = new ExecResult(); - execResult.setExecResult(true); - // config - GenerateServiceConfigCommand generateServiceConfigCommand = new GenerateServiceConfigCommand(); - generateServiceConfigCommand.setServiceName(serviceRoleInfo.getParentName()); - generateServiceConfigCommand.setCofigFileMap(serviceRoleInfo.getConfigFileMap()); - generateServiceConfigCommand.setDecompressPackageName(serviceRoleInfo.getDecompressPackageName()); - generateServiceConfigCommand.setRunAs(serviceRoleInfo.getRunAs()); - if ("zkserver".equalsIgnoreCase(serviceRoleInfo.getName())) { - generateServiceConfigCommand.setMyid((Integer) CacheUtils.get("zkserver_" + serviceRoleInfo.getHostname())); +public class ServiceConfigureAsyncHandler extends ServiceHandler { + + private final OnComplete function; + + public ServiceConfigureAsyncHandler(OnComplete function) { + this.function = function; } - generateServiceConfigCommand.setServiceRoleName(serviceRoleInfo.getName()); - ActorSelection configActor = ActorUtils.actorSystem.actorSelection( - "akka.tcp://datasophon@" + serviceRoleInfo.getHostname() + ":2552/user/worker/configureServiceActor"); - - Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); - final Future configureFuture = Patterns.ask(configActor, generateServiceConfigCommand, timeout); - configureFuture.onComplete(new OnComplete() { - @Override - public void onComplete(Throwable failure, Object success) throws Throwable { - if (failure != null) { - function.onComplete(failure, success); - } else { - ExecResult configResult = (ExecResult) success; - if (Objects.nonNull(configResult) && configResult.getExecResult() && Objects.nonNull(getNext())) { - getNext().handlerRequest(serviceRoleInfo); - } + + @Override + public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) { + ExecResult execResult = new ExecResult(); + execResult.setExecResult(true); + // config + GenerateServiceConfigCommand generateServiceConfigCommand = new GenerateServiceConfigCommand(); + generateServiceConfigCommand.setServiceName(serviceRoleInfo.getParentName()); + generateServiceConfigCommand.setCofigFileMap(serviceRoleInfo.getConfigFileMap()); + generateServiceConfigCommand.setDecompressPackageName(serviceRoleInfo.getDecompressPackageName()); + generateServiceConfigCommand.setRunAs(serviceRoleInfo.getRunAs()); + if ("zkserver".equalsIgnoreCase(serviceRoleInfo.getName())) { + generateServiceConfigCommand.setMyid((Integer) CacheUtils.get("zkserver_" + serviceRoleInfo.getHostname())); } - } - }, ActorUtils.actorSystem.dispatcher()); - return execResult; - } + generateServiceConfigCommand.setServiceRoleName(serviceRoleInfo.getName()); + ActorSelection configActor = ActorUtils.actorSystem.actorSelection( + "akka.tcp://datasophon@" + serviceRoleInfo.getHostname() + ":2552/user/worker/configureServiceActor"); + + Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); + final Future configureFuture = Patterns.ask(configActor, generateServiceConfigCommand, timeout); + configureFuture.onComplete(new OnComplete() { + + @Override + public void onComplete(Throwable failure, Object success) throws Throwable { + if (failure != null) { + function.onComplete(failure, success); + } else { + ExecResult configResult = (ExecResult) success; + if (Objects.nonNull(configResult) && configResult.getExecResult() && Objects.nonNull(getNext())) { + getNext().handlerRequest(serviceRoleInfo); + } + } + } + }, ActorUtils.actorSystem.dispatcher()); + return execResult; + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureHandler.java index 820750e3..39154203 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceConfigureHandler.java @@ -35,7 +35,7 @@ import akka.util.Timeout; public class ServiceConfigureHandler extends ServiceHandler { - + @Override public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Exception { // config @@ -50,7 +50,7 @@ public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Excepti generateServiceConfigCommand.setServiceRoleName(serviceRoleInfo.getName()); ActorSelection configActor = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + serviceRoleInfo.getHostname() + ":2552/user/worker/configureServiceActor"); - + Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); Future configureFuture = Patterns.ask(configActor, generateServiceConfigCommand, timeout); try { diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceHandler.java index dda7af59..a14d043c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceHandler.java @@ -24,9 +24,9 @@ @Data public abstract class ServiceHandler { - + private ServiceHandler next; - + public abstract ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Exception; - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceInstallHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceInstallHandler.java index b24d05cf..23434f01 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceInstallHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceInstallHandler.java @@ -18,8 +18,8 @@ package com.datasophon.api.master.handler.service; import com.datasophon.api.master.ActorUtils; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.utils.SpringTool; import com.datasophon.common.Constants; import com.datasophon.common.command.InstallServiceRoleCommand; @@ -45,7 +45,7 @@ import cn.hutool.core.io.FileUtil; public class ServiceInstallHandler extends ServiceHandler { - + private static final Logger logger = LoggerFactory.getLogger(ServiceInstallHandler.class); @Override public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Exception { @@ -70,22 +70,22 @@ public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Excepti installServiceRoleCommand.setRunAs(serviceRoleInfo.getRunAs()); installServiceRoleCommand.setServiceRoleType(serviceRoleInfo.getRoleType()); installServiceRoleCommand.setResourceStrategies(serviceRoleInfo.getResourceStrategies()); - - String md5 ; + + String md5; if ("aarch64".equals(hostEntity.getCpuArchitecture()) && FileUtil.exist(Constants.MASTER_MANAGE_PACKAGE_PATH + Constants.SLASH + serviceRoleInfo.getDecompressPackageName() + "-arm.tar.gz")) { installServiceRoleCommand.setPackageName(serviceRoleInfo.getDecompressPackageName() + "-arm.tar.gz"); logger.info("find arm package {}", installServiceRoleCommand.getPackageName()); md5 = FileUtil.readString(Constants.MASTER_MANAGE_PACKAGE_PATH + Constants.SLASH + serviceRoleInfo.getDecompressPackageName() + "-arm.tar.gz.md5", Charset.defaultCharset()); - }else { + } else { installServiceRoleCommand.setPackageName(serviceRoleInfo.getPackageName()); md5 = FileUtil.readString( Constants.MASTER_MANAGE_PACKAGE_PATH + Constants.SLASH + serviceRoleInfo.getPackageName() + ".md5", Charset.defaultCharset()); } installServiceRoleCommand.setPackageMd5(md5); - + ActorSelection actorSelection = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + serviceRoleInfo.getHostname() + ":2552/user/worker/installServiceActor"); Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStartHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStartHandler.java index 981c13ec..78721c4f 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStartHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStartHandler.java @@ -17,9 +17,6 @@ package com.datasophon.api.master.handler.service; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.master.ActorUtils; import com.datasophon.common.Constants; @@ -28,8 +25,7 @@ import com.datasophon.common.enums.ServiceRoleType; import com.datasophon.common.model.ServiceRoleInfo; import com.datasophon.common.utils.ExecResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -38,10 +34,17 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; -public class ServiceStartHandler extends ServiceHandler { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(ServiceStartHandler.class); +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class ServiceStartHandler extends ServiceHandler { + + private static final Logger logger = LoggerFactory.getLogger(ServiceStartHandler.class); + @Override public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Exception { logger.info("start to start service {} in {}", serviceRoleInfo.getName(), serviceRoleInfo.getHostname()); @@ -57,9 +60,9 @@ public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Excepti serviceRoleOperateCommand.setCommandType(serviceRoleInfo.getCommandType()); serviceRoleOperateCommand.setMasterHost(serviceRoleInfo.getMasterHost()); serviceRoleOperateCommand.setManagerHost(CacheUtils.getString(Constants.HOSTNAME)); - + logger.info("service master host is {}", serviceRoleInfo.getMasterHost()); - + serviceRoleOperateCommand.setEnableRangerPlugin(serviceRoleInfo.getEnableRangerPlugin()); serviceRoleOperateCommand.setRunAs(serviceRoleInfo.getRunAs()); Boolean enableKerberos = @@ -67,15 +70,16 @@ public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Excepti logger.info("{} enable kerberos is {}", serviceRoleInfo.getParentName(), enableKerberos); serviceRoleOperateCommand.setEnableKerberos(enableKerberos); if (serviceRoleInfo.getRoleType() == ServiceRoleType.CLIENT) { - - if(serviceRoleInfo.getName().equals("FlinkClient") && enableKerberos){ + + if (serviceRoleInfo.getName().equals("FlinkClient") && enableKerberos) { logger.info("when serviceRoleInfo name is FlinkClient ,start to startActor!"); ActorSelection startActors = ActorUtils.actorSystem.actorSelection( - "akka.tcp://datasophon@" + serviceRoleInfo.getHostname() + ":2552/user/worker/startServiceActor"); + "akka.tcp://datasophon@" + serviceRoleInfo.getHostname() + + ":2552/user/worker/startServiceActor"); Timeout timeouts = new Timeout(Duration.create(180, TimeUnit.SECONDS)); - Await.result(Patterns.ask(startActors, serviceRoleOperateCommand, timeouts),timeouts.duration()); + Await.result(Patterns.ask(startActors, serviceRoleOperateCommand, timeouts), timeouts.duration()); } - + ExecResult execResult = new ExecResult(); execResult.setExecResult(true); if (Objects.nonNull(getNext())) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStopHandler.java b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStopHandler.java index 775ca5c4..ad027933 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStopHandler.java +++ b/datasophon-service/src/main/java/com/datasophon/api/master/handler/service/ServiceStopHandler.java @@ -17,14 +17,12 @@ package com.datasophon.api.master.handler.service; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.master.ActorUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; import com.datasophon.common.enums.ServiceRoleType; import com.datasophon.common.model.ServiceRoleInfo; import com.datasophon.common.utils.ExecResult; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -32,8 +30,12 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; -public class ServiceStopHandler extends ServiceHandler { +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class ServiceStopHandler extends ServiceHandler { + @Override public ExecResult handlerRequest(ServiceRoleInfo serviceRoleInfo) throws Exception { // 停止 diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/AlertGroupService.java b/datasophon-service/src/main/java/com/datasophon/api/service/AlertGroupService.java index 45c66524..b8b76e1e 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/AlertGroupService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/AlertGroupService.java @@ -17,10 +17,11 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.AlertGroupEntity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 告警组表 * @@ -29,8 +30,8 @@ * @date 2022-03-15 17:36:08 */ public interface AlertGroupService extends IService { - + Result getAlertGroupList(Integer clusterId, String alertGroupName, Integer page, Integer pageSize); - + Result saveAlertGroup(AlertGroupEntity alertGroup); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertExpressionService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertExpressionService.java index 0f17d94d..98ba9246 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertExpressionService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertExpressionService.java @@ -17,9 +17,10 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterAlertExpression; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 表达式常量表 * @@ -28,5 +29,5 @@ * @date 2022-06-07 12:04:38 */ public interface ClusterAlertExpressionService extends IService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertGroupMapService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertGroupMapService.java index fcd44e06..8d3e56d6 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertGroupMapService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertGroupMapService.java @@ -17,9 +17,10 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterAlertGroupMap; +import com.baomidou.mybatisplus.extension.service.IService; + /** * * @@ -28,5 +29,5 @@ * @date 2022-07-13 10:01:06 */ public interface ClusterAlertGroupMapService extends IService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertHistoryService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertHistoryService.java index 5687d9aa..fd70083d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertHistoryService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertHistoryService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterAlertHistory; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群告警历史表 * @@ -31,12 +32,12 @@ * @date 2022-06-07 12:04:38 */ public interface ClusterAlertHistoryService extends IService { - + void saveAlertHistory(String alertMessage); - + Result getAlertList(Integer serviceInstanceId); - + Result getAllAlertList(Integer clusterId, Integer page, Integer pageSize); - + void removeAlertByRoleInstanceIds(List ids); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertQuotaService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertQuotaService.java index 623d2e44..550396af 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertQuotaService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertQuotaService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterAlertQuota; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群告警指标表 * @@ -31,14 +32,14 @@ * @date 2022-06-24 15:10:41 */ public interface ClusterAlertQuotaService extends IService { - + Result getAlertQuotaList(Integer clusterId, Integer alertGroupId, String quotaName, Integer page, Integer pageSize); - + void start(Integer clusterId, String alertQuotaIds); - + void stop(Integer clusterId, String alertQuotaIds); - + void saveAlertQuota(ClusterAlertQuota clusterAlertQuota); - + List listAlertQuotaByServiceName(String serviceName); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertRuleService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertRuleService.java index 76f31f71..d6ba67b2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertRuleService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterAlertRuleService.java @@ -17,9 +17,10 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterAlertRule; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 规则表 * @@ -28,5 +29,5 @@ * @date 2022-06-07 12:04:38 */ public interface ClusterAlertRuleService extends IService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterGroupService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterGroupService.java index 617cde8f..b23088ad 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterGroupService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterGroupService.java @@ -17,24 +17,25 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterGroup; import java.util.List; -public interface ClusterGroupService extends IService { +import com.baomidou.mybatisplus.extension.service.IService; +public interface ClusterGroupService extends IService { + Result saveClusterGroup(Integer clusterId, String groupName); - + void refreshUserGroupToHost(Integer clusterId); - + Result deleteUserGroup(Integer id); - + Result listPage(String groupName, Integer clusterId, Integer page, Integer pageSize); - + List listAllUserGroup(Integer clusterId); - + void createUnixGroupOnHost(String hostname, String groupName); - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterInfoService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterInfoService.java index d5b36bf9..7abdb6fd 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterInfoService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterInfoService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterInfoEntity; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群信息表 * @@ -31,20 +32,20 @@ * @date 2022-03-15 17:36:08 */ public interface ClusterInfoService extends IService { - + ClusterInfoEntity getClusterByClusterCode(String clusterCode); - + Result saveCluster(ClusterInfoEntity clusterInf); - + Result getClusterList(); - + Result runningClusterList(); - + Result updateClusterState(Integer clusterId, Integer clusterState); - + List getClusterByFrameCode(String frameCode); - + Result updateCluster(ClusterInfoEntity clusterInfo); - + void deleteCluster(List asList); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterKerberosService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterKerberosService.java index ee34fac9..51c197f3 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterKerberosService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterKerberosService.java @@ -17,15 +17,16 @@ package com.datasophon.api.service; -import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -public interface ClusterKerberosService { +import org.springframework.web.multipart.MultipartFile; +public interface ClusterKerberosService { + void downloadKeytab(Integer clusterId, String principal, String keytabName, String hostname, HttpServletResponse response) throws IOException; - + void uploadKeytab(MultipartFile file, String hostname, String keytabFileName) throws IOException; } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterNodeLabelService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterNodeLabelService.java index 2d96b180..2007090c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterNodeLabelService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterNodeLabelService.java @@ -17,21 +17,22 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterNodeLabelEntity; import java.util.List; -public interface ClusterNodeLabelService extends IService { +import com.baomidou.mybatisplus.extension.service.IService; +public interface ClusterNodeLabelService extends IService { + Result saveNodeLabel(Integer clusterId, String nodeLabel); - + Result deleteNodeLabel(Integer nodeLabelId); - + Result assignNodeLabel(Integer nodeLabelId, String hostIds); - + List queryClusterNodeLabel(Integer clusterId); - + void createDefaultNodeLabel(Integer id); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterQueueCapacityService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterQueueCapacityService.java index e41bbbb6..c4ffefd8 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterQueueCapacityService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterQueueCapacityService.java @@ -17,10 +17,11 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterQueueCapacity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * * @@ -29,10 +30,10 @@ * @date 2022-11-25 14:30:11 */ public interface ClusterQueueCapacityService extends IService { - + Result refreshToYarn(Integer clusterId) throws Exception; - + void createDefaultQueue(Integer id); - + Result listCapacityQueue(Integer clusterId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRackService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRackService.java index 809e25d4..bb02896a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRackService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRackService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterRack; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * * @@ -31,12 +32,12 @@ * @date 2022-11-25 11:31:59 */ public interface ClusterRackService extends IService { - + List queryClusterRack(Integer clusterId); - + void saveRack(Integer clusterId, String rack); - + Result deleteRack(Integer rackId); - + void createDefaultRack(Integer clusterId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRoleUserService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRoleUserService.java index 30f6c0fd..3422be39 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRoleUserService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterRoleUserService.java @@ -17,13 +17,14 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterRoleUserEntity; import com.datasophon.dao.entity.UserInfoEntity; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群角色用户中间表 * @@ -32,10 +33,10 @@ * @date 2022-03-15 17:36:08 */ public interface ClusterRoleUserService extends IService { - + boolean isClusterManager(Integer id, String clusterId); - + Result saveClusterManager(Integer clusterId, String userIds); - + List getAllClusterManagerByClusterId(Integer id); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostCommandService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostCommandService.java index b1a9bc69..ceed9cbf 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostCommandService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostCommandService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceCommandHostCommandEntity; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务操作指令主机指令表 * @@ -31,22 +32,22 @@ * @date 2022-04-12 11:28:06 */ public interface ClusterServiceCommandHostCommandService extends IService { - + Result getHostCommandList(String hostname, String commandHostId, Integer page, Integer pageSize); - + List getHostCommandListByCommandId(String id); - + ClusterServiceCommandHostCommandEntity getByHostCommandId(String hostCommandId); - + void updateByHostCommandId(ClusterServiceCommandHostCommandEntity hostCommand); - + Integer getHostCommandSizeByHostnameAndCommandHostId(String hostname, String commandHostId); - + Integer getHostCommandTotalProgressByHostnameAndCommandHostId(String hostname, String commandHostId); - + Result getHostCommandLog(Integer clusterId, String hostCommandId) throws Exception; - + List findFailedHostCommand(String hostname, String commandHostId); - + List findCanceledHostCommand(String hostname, String commandHostId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostService.java index fa090be8..58aae920 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandHostService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceCommandHostEntity; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务操作指令主机表 * @@ -31,14 +32,14 @@ * @date 2022-04-12 11:28:06 */ public interface ClusterServiceCommandHostService extends IService { - + Result getCommandHostList(Integer clusterId, String commandId, Integer page, Integer pageSize); - + Integer getCommandHostSizeByCommandId(String commandId); - + Integer getCommandHostTotalProgressByCommandId(String commandId); - + List findFailedCommandHost(String commandId); - + List findCanceledCommandHost(String commandId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandService.java index a5dc8172..f04fa7ab 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceCommandService.java @@ -17,7 +17,6 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.enums.CommandType; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceCommandEntity; @@ -25,6 +24,8 @@ import java.util.List; import java.util.Map; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务操作指令表 * @@ -33,24 +34,24 @@ * @date 2022-04-12 11:28:06 */ public interface ClusterServiceCommandService extends IService { - + Result generateCommand(Integer clusterId, CommandType commandType, List serviceNames); - + Result getServiceCommandlist(Integer clusterId, Integer page, Integer pageSize); - + Result generateServiceCommand(Integer clusterId, CommandType command, List ids); - + Result generateServiceRoleCommands(Integer clusterId, CommandType commandType, Map> instanceIdMap); - + Result generateServiceRoleCommand(Integer clusterId, CommandType command, Integer serviceIntanceId, List ids); - + void startExecuteCommand(Integer clusterId, String commandType, String commandIds); - + void cancelCommand(String commandId); - + ClusterServiceCommandEntity getLastRestartCommand(Integer id); - + ClusterServiceCommandEntity getCommandById(String commandId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceDashboardService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceDashboardService.java index 2ffd9737..a9b3eb29 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceDashboardService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceDashboardService.java @@ -17,10 +17,11 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceDashboard; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务总览仪表盘 * @@ -29,6 +30,6 @@ * @date 2022-06-23 17:01:58 */ public interface ClusterServiceDashboardService extends IService { - + Result getDashboardUrl(Integer clusterId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceConfigService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceConfigService.java index aef9925a..42492f8c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceConfigService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceConfigService.java @@ -17,10 +17,11 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceInstanceConfigEntity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务角色实例配置表 * @@ -29,11 +30,11 @@ * @date 2022-04-24 16:25:17 */ public interface ClusterServiceInstanceConfigService extends IService { - + Result getServiceInstanceConfig(Integer serviceInstanceId, Integer version, Integer roleGroupId, Integer page, Integer pageSize); - + ClusterServiceInstanceConfigEntity getServiceConfigByServiceId(Integer id); - + Result getConfigVersion(Integer serviceInstanceId, Integer roleGroupId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceRoleGroupService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceRoleGroupService.java index 1f0c0b94..44aee85d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceRoleGroupService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceRoleGroupService.java @@ -19,31 +19,32 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceInstanceRoleGroup; import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + public interface ClusterServiceInstanceRoleGroupService extends IService { - + ClusterServiceInstanceRoleGroup getRoleGroupByServiceInstanceId(Integer id); - + Result saveRoleGroup(Integer serviceInstanceId, Integer roleGroupId, String roleGroupName); - + Result bind(String roleInstanceIds, Integer roleGroupId); - + ClusterServiceRoleGroupConfig getRoleGroupConfigByServiceId(Integer id); - + Result rename(Integer roleGroupId, String roleGroupName); - + Result deleteRoleGroup(Integer roleGroupId); - + List listRoleGroupByServiceInstanceId( Integer serviceInstanceId); - + void updateToNeedRestart(Integer roleGroupId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceService.java index 9a2548b5..671d4b98 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceInstanceService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceInstanceEntity; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务表 * @@ -31,22 +32,22 @@ * @date 2022-04-24 16:25:17 */ public interface ClusterServiceInstanceService extends IService { - + ClusterServiceInstanceEntity getServiceInstanceByClusterIdAndServiceName(Integer clusterId, String parentName); - + String getServiceConfigByClusterIdAndServiceName(Integer id, String node); - + List listAll(Integer clusterId); - + Result downloadClientConfig(Integer clusterId, String serviceName); - + Result getServiceRoleType(Integer serviceInstanceId); - + Result configVersionCompare(Integer serviceInstanceId, Integer roleGroupId); - + Result delServiceInstance(Integer serviceInstanceId); - + List listRunningServiceInstance(Integer clusterId); - + boolean hasRunningRoleInstance(Integer serviceInstanceId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleGroupConfigService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleGroupConfigService.java index dcd855f2..e51e53fe 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleGroupConfigService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleGroupConfigService.java @@ -17,11 +17,12 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * * @@ -30,12 +31,12 @@ * @date 2022-08-16 16:56:01 */ public interface ClusterServiceRoleGroupConfigService extends IService { - + ClusterServiceRoleGroupConfig getConfigByRoleGroupId(Integer roleGroupId); - + ClusterServiceRoleGroupConfig getConfigByRoleGroupIdAndVersion(Integer roleGroupId, Integer version); - + void removeAllByRoleGroupId(Integer roleGroupId); - + List listRoleGroupConfigsByRoleGroupIds(List roleGroupIds); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceConfigService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceConfigService.java index 5afc2776..12407d47 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceConfigService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceConfigService.java @@ -17,9 +17,10 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterServiceRoleInstanceConfigEntity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务角色实例配置表 * @@ -28,5 +29,5 @@ * @date 2022-03-15 17:36:08 */ public interface ClusterServiceRoleInstanceConfigService extends IService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceService.java index d8335ded..68c600aa 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceService.java @@ -17,13 +17,14 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.ServiceRoleState; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务角色实例表 * @@ -32,55 +33,54 @@ * @date 2022-04-24 16:25:17 */ public interface ClusterServiceRoleInstanceService extends IService { - + List listStoppedServiceRoleListByHostnameAndClusterId(String hostname, Integer clusterId); - + List getServiceRoleListByHostnameAndClusterId(String hostname, Integer clusterId); - + List getServiceRoleInstanceListByServiceIdAndRoleState(Integer id, ServiceRoleState stop); - + ClusterServiceRoleInstanceEntity getOneServiceRole(String serviceRoleName, String hostname, Integer clusterId); - + Result listAll(Integer serviceInstanceId, String hostname, Integer serviceRoleState, String serviceRoleName, Integer roleGroupId, Integer page, Integer pageSize); - + Result getLog(Integer serviceRoleInstanceId) throws Exception; - + List getServiceRoleInstanceListByServiceId(int id); - + List getServiceRoleInstanceListByClusterId(int clusterId); - + Result deleteServiceRole(List idList); - + List getServiceRoleInstanceListByClusterIdAndRoleName(Integer clusterId, String roleName); - + List getRunningServiceRoleInstanceListByServiceId(Integer serviceInstanceId); - + Result restartObsoleteService(Integer roleGroupId); - + Result decommissionNode(String serviceRoleInstanceIds, String serviceName) throws Exception; - + void updateToNeedRestart(Integer roleGroupId); - + void updateToNeedRestartByHost(String hostName); - + List getObsoleteService(Integer id); - + List getStoppedRoleInstanceOnHost(Integer clusterId, String hostname, ServiceRoleState state); - + void reomveRoleInstance(Integer serviceInstanceId); - + ClusterServiceRoleInstanceEntity getKAdminRoleIns(Integer clusterId); - + List listServiceRoleByName(String alertManager); - + ClusterServiceRoleInstanceEntity getServiceRoleInsByHostAndName(String hostName, String serviceRoleName); - + List listRoleIns(String hostname, String serviceName); - - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceWebuisService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceWebuisService.java index 67ffef55..0da413f1 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceWebuisService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterServiceRoleInstanceWebuisService.java @@ -17,13 +17,14 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceRoleInstanceWebuis; import java.util.ArrayList; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群服务角色对应web ui表 * @@ -32,18 +33,18 @@ * @date 2022-04-24 16:25:17 */ public interface ClusterServiceRoleInstanceWebuisService extends IService { - + Result getWebUis(Integer serviceInstanceId); - + void removeByServiceInsId(Integer serviceInstanceId); - + void updateWebUiToActive(Integer id); - + ClusterServiceRoleInstanceWebuis getRoleInstanceWebUi(Integer roleInstanceId); - + void removeByRoleInsIds(ArrayList needRemoveList); - + void updateWebUiToStandby(Integer id); - + List listWebUisByServiceInstanceId(Integer serviceInstanceId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserGroupService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserGroupService.java index 6e0bde92..21e2201c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserGroupService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserGroupService.java @@ -17,22 +17,23 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterGroup; import com.datasophon.dao.entity.ClusterUser; import com.datasophon.dao.entity.ClusterUserGroup; import java.util.List; -public interface ClusterUserGroupService extends IService { +import com.baomidou.mybatisplus.extension.service.IService; +public interface ClusterUserGroupService extends IService { + Integer countGroupUserNum(Integer id); - + void deleteByUser(Integer id); - + ClusterGroup queryMainGroup(Integer id); - + List listOtherGroups(Integer userId); - + List listClusterUsers(Integer groupId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserService.java index 9a3a7ff0..fcf82399 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterUserService.java @@ -17,21 +17,22 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterUser; import java.util.List; -public interface ClusterUserService extends IService { +import com.baomidou.mybatisplus.extension.service.IService; +public interface ClusterUserService extends IService { + Result create(Integer clusterId, String username, Integer mainGroupId, String otherGroupIds); - + Result listPage(Integer clusterId, String username, Integer page, Integer pageSize); - + Result deleteClusterUser(Integer id); - + List listAllUser(Integer clusterId); - + void createUnixUserOnHost(ClusterUser clusterUser, String hostname); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterVariableService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterVariableService.java index eb9cee00..3c492e6d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterVariableService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterVariableService.java @@ -17,11 +17,12 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterVariable; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * * @@ -30,8 +31,8 @@ * @date 2022-06-14 15:50:36 */ public interface ClusterVariableService extends IService { - + ClusterVariable getVariableByVariableName(String variableName, Integer clusterId); - + List getVariables(Integer clusterId, String serviceName); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnQueueService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnQueueService.java index 5a3d0574..8d328e4a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnQueueService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnQueueService.java @@ -17,10 +17,11 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterYarnQueue; +import com.baomidou.mybatisplus.extension.service.IService; + /** * * @@ -29,8 +30,8 @@ * @date 2022-07-13 19:34:14 */ public interface ClusterYarnQueueService extends IService { - + Result listByPage(Integer clusterId, Integer page, Integer pageSize); - + Result refreshQueues(Integer clusterId) throws Exception; } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnSchedulerService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnSchedulerService.java index 9c9a6897..54d9abc3 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnSchedulerService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterYarnSchedulerService.java @@ -17,9 +17,10 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterYarnScheduler; +import com.baomidou.mybatisplus.extension.service.IService; + /** * * @@ -28,8 +29,8 @@ * @date 2022-11-25 15:02:11 */ public interface ClusterYarnSchedulerService extends IService { - + ClusterYarnScheduler getScheduler(Integer clusterId); - + void createDefaultYarnScheduler(Integer clusterId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterZkService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterZkService.java index ba447fb1..31b97f56 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ClusterZkService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ClusterZkService.java @@ -17,14 +17,15 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.ClusterZk; import java.util.List; -public interface ClusterZkService extends IService { +import com.baomidou.mybatisplus.extension.service.IService; +public interface ClusterZkService extends IService { + Integer getMaxMyId(Integer clusterId); - + List getAllZkServer(Integer clusterId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/FrameInfoService.java b/datasophon-service/src/main/java/com/datasophon/api/service/FrameInfoService.java index 955b319f..ff039572 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/FrameInfoService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/FrameInfoService.java @@ -17,10 +17,11 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.FrameInfoEntity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群框架表 * @@ -29,6 +30,6 @@ * @date 2022-03-15 17:36:08 */ public interface FrameInfoService extends IService { - + Result getAllClusterFrame(); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceRoleService.java b/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceRoleService.java index 53bf9f36..77ca4d2d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceRoleService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceRoleService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.FrameServiceRoleEntity; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 框架服务角色表 * @@ -31,16 +32,16 @@ * @date 2022-04-18 14:38:53 */ public interface FrameServiceRoleService extends IService { - + Result getServiceRoleList(Integer clusterId, String serviceIds, Integer serviceRoleType); - + FrameServiceRoleEntity getServiceRoleByServiceIdAndServiceRoleName(Integer id, String name); - + FrameServiceRoleEntity getServiceRoleByFrameCodeAndServiceRoleName(String clusterFrame, String serviceRoleName); - + Result getNonMasterRoleList(Integer clusterId, String serviceIds); - + Result getServiceRoleByServiceName(Integer clusterId, String serviceName); - + List getAllServiceRoleList(Integer frameServiceId); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceService.java b/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceService.java index 233d8258..86978b29 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/FrameServiceService.java @@ -17,12 +17,13 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.FrameServiceEntity; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 集群框架版本服务表 * @@ -31,16 +32,16 @@ * @date 2022-03-15 17:36:08 */ public interface FrameServiceService extends IService { - + Result getAllFrameService(Integer clusterId); - + Result getServiceListByServiceIds(List serviceIds); - + FrameServiceEntity getServiceByFrameIdAndServiceName(Integer id, String serviceName); - + FrameServiceEntity getServiceByFrameCodeAndServiceName(String clusterFrame, String serviceName); - + List getAllFrameServiceByFrameCode(String clusterFrame); - + List listServices(String serviceIds); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/InstallService.java b/datasophon-service/src/main/java/com/datasophon/api/service/InstallService.java index 2b65bf29..4dbfd085 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/InstallService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/InstallService.java @@ -20,29 +20,28 @@ import com.datasophon.common.utils.Result; public interface InstallService { - + Result getInstallStep(Integer type); - + Result analysisHostList(Integer clusterId, String hosts, String sshUser, Integer sshPort, Integer page, Integer pageSize); - + Result getHostCheckStatus(Integer clusterId, String sshUser, Integer sshPort); - + Result rehostCheck(Integer clusterId, String hostnames, String sshUser, Integer sshPort); - + Result dispatcherHostAgentList(Integer id, Integer installStateCode, Integer page, Integer clusterId); - + Result reStartDispatcherHostAgent(Integer clusterId, String hostnames); - + Result hostCheckCompleted(Integer clusterId); - + Result cancelDispatcherHostAgent(Integer clusterId, String hostname, Integer installStateCode); - + Result dispatcherHostAgentCompleted(Integer clusterId); - + Result generateHostAgentCommand(String clusterHostIds, String commandType) throws Exception; - - + /** * 启动/停止 主机上安装的服务启动 * @param clusterHostIds diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/NoticeGroupUserService.java b/datasophon-service/src/main/java/com/datasophon/api/service/NoticeGroupUserService.java index b61f6c76..810445f0 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/NoticeGroupUserService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/NoticeGroupUserService.java @@ -17,9 +17,10 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.NoticeGroupUserEntity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 通知组-用户中间表 * @@ -28,5 +29,5 @@ * @date 2022-03-15 17:36:08 */ public interface NoticeGroupUserService extends IService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/RoleInfoService.java b/datasophon-service/src/main/java/com/datasophon/api/service/RoleInfoService.java index 02c058a5..bbab8379 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/RoleInfoService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/RoleInfoService.java @@ -17,9 +17,10 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.RoleInfoEntity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 角色信息表 * @@ -28,5 +29,5 @@ * @date 2022-03-15 17:36:08 */ public interface RoleInfoService extends IService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ServiceInstallService.java b/datasophon-service/src/main/java/com/datasophon/api/service/ServiceInstallService.java index 8fd35d31..38cbeb5c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ServiceInstallService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ServiceInstallService.java @@ -22,31 +22,32 @@ import com.datasophon.common.model.ServiceRoleHostMapping; import com.datasophon.common.utils.Result; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; -public interface ServiceInstallService { +import javax.servlet.http.HttpServletResponse; +public interface ServiceInstallService { + Result getServiceConfigOption(Integer clusterId, String serviceName); - + Result saveServiceRoleHostMapping(Integer clusterId, List list); - + Result saveServiceConfig(Integer clusterId, String serviceName, List configJson, Integer roleGroupId); - + Result saveHostServiceRoleMapping(Integer clusterId, List list); - + Result getServiceRoleDeployOverview(Integer clusterId); - + Result startInstallService(Integer clusterId, List commandIds); - + void downloadPackage(String packageName, HttpServletResponse response) throws IOException; - + void downloadResource(String frameCode, String serviceRoleName, String resource, HttpServletResponse response) throws IOException; - + Result getServiceRoleHostMapping(Integer clusterId); - + Result checkServiceDependency(Integer clusterId, String serviceIds); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/ServiceOperateStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/service/ServiceOperateStrategy.java index a9da9ea4..1d99a2c0 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/ServiceOperateStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/ServiceOperateStrategy.java @@ -18,5 +18,5 @@ package com.datasophon.api.service; public interface ServiceOperateStrategy { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/SessionService.java b/datasophon-service/src/main/java/com/datasophon/api/service/SessionService.java index 1d07271d..11e828a5 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/SessionService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/SessionService.java @@ -17,22 +17,23 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.dao.entity.SessionEntity; import com.datasophon.dao.entity.UserInfoEntity; import javax.servlet.http.HttpServletRequest; +import com.baomidou.mybatisplus.extension.service.IService; + /** * @author gaodayu * @email gaodayu2022@163.com * @date 2022-03-16 11:40:00 */ public interface SessionService extends IService { - + SessionEntity getSession(HttpServletRequest request); - + String createSession(UserInfoEntity user, String ip); - + void signOut(String ip, UserInfoEntity loginUser); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/UserInfoService.java b/datasophon-service/src/main/java/com/datasophon/api/service/UserInfoService.java index 6a39f930..b2a56d0e 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/UserInfoService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/UserInfoService.java @@ -17,10 +17,11 @@ package com.datasophon.api.service; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.UserInfoEntity; +import com.baomidou.mybatisplus.extension.service.IService; + /** * 用户信息表 * @@ -29,10 +30,10 @@ * @date 2022-03-15 17:36:08 */ public interface UserInfoService extends IService { - + UserInfoEntity queryUser(String username, String password); - + Result createUser(UserInfoEntity userInfo); - + Result getUserListByPage(String username, Integer page, Integer pageSize); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/host/ClusterHostService.java b/datasophon-service/src/main/java/com/datasophon/api/service/host/ClusterHostService.java index c185175e..7104bfbe 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/host/ClusterHostService.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/host/ClusterHostService.java @@ -17,25 +17,24 @@ package com.datasophon.api.service.host; -import com.baomidou.mybatisplus.extension.service.IService; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterHostDO; import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; public interface ClusterHostService extends IService { - + ClusterHostDO getClusterHostByHostname(String hostname); - + Result listByPage(Integer clusterId, String hostname, String ip, String cpuArchitecture, Integer hostState, String orderField, String orderType, Integer page, Integer pageSize); - + List getHostListByClusterId(Integer id); - + Result getRoleListByHostname(Integer clusterId, String hostname); - - + /** * 批量删除主机。 * 删除主机,首先停止主机上的服务 @@ -46,16 +45,16 @@ Result listByPage(Integer clusterId, String hostname, String ip, String cpuArchi * @return */ Result deleteHosts(String hostIds); - + Result getRack(Integer clusterId); - + void removeHostByClusterId(Integer id); - + void updateBatchNodeLabel(List hostIds, String nodeLabel); - + List getHostListByIds(List ids); - + Result assignRack(Integer clusterId, String rack, String hostIds); - + List getClusterHostByRack(Integer clusterId, String rack); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/host/dto/QueryHostListPageDTO.java b/datasophon-service/src/main/java/com/datasophon/api/service/host/dto/QueryHostListPageDTO.java index 14ed2f33..5c928f2c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/host/dto/QueryHostListPageDTO.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/host/dto/QueryHostListPageDTO.java @@ -1,13 +1,14 @@ package com.datasophon.api.service.host.dto; import com.datasophon.domain.host.enums.MANAGED; -import lombok.Data; import java.util.Date; +import lombok.Data; + @Data public class QueryHostListPageDTO { - + private Integer id; /** * 创建时间 @@ -65,10 +66,10 @@ public class QueryHostListPageDTO { * 1:受管 2:断线 */ private MANAGED managed; - + private String cpuArchitecture; - + private String nodeLabel; - + private Integer serviceRoleNum; } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/host/impl/ClusterHostServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/host/impl/ClusterHostServiceImpl.java index 5a3d0e2b..082de78a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/host/impl/ClusterHostServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/host/impl/ClusterHostServiceImpl.java @@ -17,19 +17,14 @@ package com.datasophon.api.service.host.impl; -import akka.actor.ActorRef; -import cn.hutool.crypto.SecureUtil; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.PrometheusActor; import com.datasophon.api.master.RackActor; -import com.datasophon.api.service.ClusterRackService; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterInfoService; +import com.datasophon.api.service.ClusterRackService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.host.dto.QueryHostListPageDTO; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; @@ -42,15 +37,13 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterRack; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import com.datasophon.domain.host.enums.HostState; import com.datasophon.dao.enums.RoleType; import com.datasophon.dao.enums.ServiceRoleState; import com.datasophon.dao.mapper.ClusterHostMapper; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; +import com.datasophon.domain.host.enums.HostState; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.duration.FiniteDuration; import java.util.ArrayList; @@ -61,31 +54,43 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorRef; +import cn.hutool.crypto.SecureUtil; + @Service("clusterHostService") @Transactional public class ClusterHostServiceImpl extends ServiceImpl implements - ClusterHostService { - + ClusterHostService { + @Autowired ClusterHostMapper hostMapper; - + @Autowired ClusterServiceRoleInstanceService roleInstanceService; - + @Autowired ClusterInfoService clusterInfoService; - + @Autowired ClusterRackService clusterRackService; - - private final String IP = "ip"; - + + private final String ip = "ip"; + @Override public ClusterHostDO getClusterHostByHostname(String hostname) { return hostMapper.getClusterHostByHostname(hostname); } - + @Override public Result listByPage(Integer clusterId, String hostname, String ip, String cpuArchitecture, Integer hostState, String orderField, String orderType, Integer page, Integer pageSize) { @@ -96,24 +101,24 @@ public Result listByPage(Integer clusterId, String hostname, String ip, String c .eq(Constants.MANAGED, 1) .eq(StringUtils.isNotBlank(cpuArchitecture), Constants.CPU_ARCHITECTURE, cpuArchitecture) .eq(hostState != null, Constants.HOST_STATE, hostState) - .like(StringUtils.isNotBlank(ip), IP, ip) + .like(StringUtils.isNotBlank(ip), this.ip, ip) .like(StringUtils.isNotBlank(hostname), Constants.HOSTNAME, hostname) .orderByAsc("asc".equals(orderType), orderField) .orderByDesc("desc".equals(orderType), orderField) .last("limit " + offset + "," + pageSize)); - + // 回显rack的名称 而不是ID Map rackMap = clusterRackService.queryClusterRack(clusterId).stream() - .collect(Collectors.toMap(obj->obj.getId()+"", ClusterRack::getRack)); + .collect(Collectors.toMap(obj -> obj.getId() + "", ClusterRack::getRack)); for (ClusterHostDO clusterHostDO : list) { QueryHostListPageDTO queryHostListPageDTO = new QueryHostListPageDTO(); - BeanUtils.copyProperties(clusterHostDO,queryHostListPageDTO); + BeanUtils.copyProperties(clusterHostDO, queryHostListPageDTO); // 查询主机上服务角色数 int serviceRoleNum = roleInstanceService.count(new QueryWrapper() .eq(Constants.HOSTNAME, clusterHostDO.getHostname())); queryHostListPageDTO.setServiceRoleNum(serviceRoleNum); queryHostListPageDTO.setHostState(clusterHostDO.getHostState().getValue()); - queryHostListPageDTO.setRack(rackMap.getOrDefault(queryHostListPageDTO.getRack(),"/default-rack")); + queryHostListPageDTO.setRack(rackMap.getOrDefault(queryHostListPageDTO.getRack(), "/default-rack")); hostListPageDTOS.add(queryHostListPageDTO); } int count = this.count(new QueryWrapper().eq(Constants.CLUSTER_ID, clusterId) @@ -123,14 +128,14 @@ public Result listByPage(Integer clusterId, String hostname, String ip, String c .like(StringUtils.isNotBlank(hostname), Constants.HOSTNAME, hostname)); return Result.success(hostListPageDTOS).put(Constants.TOTAL, count); } - + @Override public List getHostListByClusterId(Integer clusterId) { return this.list(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId) .eq(Constants.MANAGED, 1)); } - + @Override public Result getRoleListByHostname(Integer clusterId, String hostname) { List list = @@ -140,8 +145,7 @@ public Result getRoleListByHostname(Integer clusterId, String hostname) { } return Result.success(list); } - - + /** * 批量删除主机。 * 删除主机,首先停止主机上的服务 @@ -165,7 +169,8 @@ public Result deleteHosts(String hostIds) { .eq(Constants.HOSTNAME, host.getHostname()) .eq(Constants.SERVICE_ROLE_STATE, ServiceRoleState.RUNNING) .ne(Constants.ROLE_TYPE, RoleType.CLIENT)); - List roles = list.stream().map(ClusterServiceRoleInstanceEntity::getServiceRoleName).collect(Collectors.toList()); + List roles = list.stream().map(ClusterServiceRoleInstanceEntity::getServiceRoleName) + .collect(Collectors.toList()); if (!list.isEmpty()) { return Result.error(host.getHostname() + Status.HOST_EXIT_ONE_RUNNING_ROLE.getMsg() + roles); } @@ -175,36 +180,36 @@ public Result deleteHosts(String hostIds) { if (CacheUtils.constainsKey(distributeAgentKey + Constants.UNDERLINE + host.getHostname())) { CacheUtils.removeKey(distributeAgentKey + Constants.UNDERLINE + host.getHostname()); } - + this.removeById(hostId); - + if (host.getHostState() != HostState.OFFLINE) { - //stop the worker on this host + // stop the worker on this host ActorRef execCmdActor = ActorUtils.getRemoteActor(host.getHostname(), "executeCmdActor"); ExecuteCmdCommand command = new ExecuteCmdCommand(); ArrayList commands = new ArrayList<>(); commands.add("service"); commands.add("datasophon-worker"); commands.add("stop"); - + command.setCommands(commands); execCmdActor.tell(command, ActorRef.noSender()); } - //remove host from prometheus + // remove host from prometheus ActorRef prometheusActor = ActorUtils.getLocalActor(PrometheusActor.class, ActorUtils.getActorRefName(PrometheusActor.class)); - + // Prometheus 移除 hosts 信息 GenerateHostPrometheusConfig prometheusConfigCommand = new GenerateHostPrometheusConfig(); prometheusConfigCommand.setClusterId(clusterInfo.getId()); - + ActorUtils.actorSystem.scheduler().scheduleOnce( FiniteDuration.apply(3L, TimeUnit.SECONDS), prometheusActor, prometheusConfigCommand, ActorUtils.actorSystem.dispatcher(), ActorRef.noSender()); - + // remove the host from the cache Map map = (Map) CacheUtils.get(clusterCode + Constants.HOST_MAP); @@ -219,8 +224,7 @@ public Result deleteHosts(String hostIds) { } return Result.success(); } - - + @Override public Result getRack(Integer clusterId) { ArrayList list = new ArrayList<>(); @@ -229,12 +233,12 @@ public Result getRack(Integer clusterId) { list.add(rack); return Result.success(list); } - + @Override public void removeHostByClusterId(Integer clusterId) { this.remove(new QueryWrapper().eq(Constants.CLUSTER_ID, clusterId)); } - + @Override public void updateBatchNodeLabel(List hostIds, String nodeLabel) { List list = this.lambdaQuery().in(ClusterHostDO::getId, hostIds).list(); @@ -243,12 +247,12 @@ public void updateBatchNodeLabel(List hostIds, String nodeLabel) { } this.updateBatchById(list); } - + @Override public List getHostListByIds(List ids) { return this.lambdaQuery().in(ClusterHostDO::getId, ids).or().in(ClusterHostDO::getHostname, ids).list(); } - + @Override public Result assignRack(Integer clusterId, String rack, String hostIds) { List ids = Arrays.asList(hostIds.split(",")); @@ -264,7 +268,7 @@ public Result assignRack(Integer clusterId, String rack, String hostIds) { rackActor.tell(command, ActorRef.noSender()); return Result.success(); } - + @Override public List getClusterHostByRack(Integer clusterId, String rack) { return this.list(new QueryWrapper() diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/AlertGroupServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/AlertGroupServiceImpl.java index e18799b8..fae4679c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/AlertGroupServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/AlertGroupServiceImpl.java @@ -17,9 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.AlertGroupService; import com.datasophon.api.service.ClusterAlertGroupMapService; import com.datasophon.api.service.ClusterAlertQuotaService; @@ -30,36 +27,42 @@ import com.datasophon.dao.entity.ClusterAlertGroupMap; import com.datasophon.dao.entity.ClusterAlertQuota; import com.datasophon.dao.mapper.AlertGroupMapper; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; + +import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("alertGroupService") public class AlertGroupServiceImpl extends ServiceImpl implements AlertGroupService { - + @Autowired private ClusterAlertGroupMapService alertGroupMapService; - + @Autowired private ClusterAlertQuotaService quotaService; - + @Override public Result getAlertGroupList(Integer clusterId, String alertGroupName, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; - + List alertGroupMapList = alertGroupMapService.list(new QueryWrapper().eq(Constants.CLUSTER_ID, clusterId)); if (CollectionUtils.isEmpty(alertGroupMapList)) { return Result.successEmptyCount(); } - + List groupIds = alertGroupMapList.stream().map(ClusterAlertGroupMap::getAlertGroupId).collect(Collectors.toList()); LambdaQueryChainWrapper wrapper = this.lambdaQuery() @@ -70,7 +73,7 @@ public Result getAlertGroupList(Integer clusterId, String alertGroupName, Intege if (CollectionUtils.isEmpty(alertGroupList)) { return Result.successEmptyCount(); } - + Set alertGroupIdList = alertGroupList.stream().map(AlertGroupEntity::getId).collect(Collectors.toSet()); // 查询告警组下告警指标个数 @@ -85,10 +88,10 @@ public Result getAlertGroupList(Integer clusterId, String alertGroupName, Intege a.setAlertQuotaNum(quotaCnt); }); } - + return Result.success(alertGroupList).put(Constants.TOTAL, count); } - + @Override public Result saveAlertGroup(AlertGroupEntity alertGroup) { this.save(alertGroup); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertExpressionServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertExpressionServiceImpl.java index 68c787ad..17ff9cbd 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertExpressionServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertExpressionServiceImpl.java @@ -17,15 +17,17 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterAlertExpressionService; import com.datasophon.dao.entity.ClusterAlertExpression; import com.datasophon.dao.mapper.ClusterAlertExpressionMapper; + import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterAlertExpressionService") public class ClusterAlertExpressionServiceImpl extends ServiceImpl implements ClusterAlertExpressionService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertGroupMapServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertGroupMapServiceImpl.java index 7b5f123f..8af49b90 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertGroupMapServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertGroupMapServiceImpl.java @@ -17,15 +17,17 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterAlertGroupMapService; import com.datasophon.dao.entity.ClusterAlertGroupMap; import com.datasophon.dao.mapper.ClusterAlertGroupMapMapper; + import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterAlertGroupMapService") public class ClusterAlertGroupMapServiceImpl extends ServiceImpl implements ClusterAlertGroupMapService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertHistoryServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertHistoryServiceImpl.java index 2b3eb22c..86784be3 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertHistoryServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertHistoryServiceImpl.java @@ -17,9 +17,6 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorRef; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.PrometheusActor; import com.datasophon.api.master.alert.AlertActor; @@ -33,28 +30,37 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.mapper.ClusterAlertHistoryMapper; + +import scala.concurrent.duration.FiniteDuration; + +import java.util.List; +import java.util.concurrent.TimeUnit; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import scala.concurrent.duration.FiniteDuration; -import java.util.List; -import java.util.concurrent.TimeUnit; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorRef; @Service("clusterAlertHistoryService") @Transactional -public class ClusterAlertHistoryServiceImpl extends ServiceImpl implements ClusterAlertHistoryService { - +public class ClusterAlertHistoryServiceImpl extends ServiceImpl + implements + ClusterAlertHistoryService { + private static final Logger logger = LoggerFactory.getLogger(ClusterAlertHistoryServiceImpl.class); - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Autowired private ClusterInfoService clusterInfoService; - + @Override public void saveAlertHistory(String alertMessage) { logger.warn("Receive Alert Message : {}", alertMessage); @@ -65,8 +71,7 @@ public void saveAlertHistory(String alertMessage) { ActorUtils.actorSystem.dispatcher(), ActorRef.noSender()); } - - + @Override public Result getAlertList(Integer serviceInstanceId) { List list = this.list(new QueryWrapper() @@ -74,7 +79,7 @@ public Result getAlertList(Integer serviceInstanceId) { .eq(Constants.IS_ENABLED, 1)); return Result.success(list); } - + @Override public Result getAllAlertList(Integer clusterId, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; @@ -88,7 +93,7 @@ public Result getAllAlertList(Integer clusterId, Integer page, Integer pageSize) .eq(Constants.IS_ENABLED, 1)); return Result.success(list).put(Constants.TOTAL, count); } - + @Override public void removeAlertByRoleInstanceIds(List ids) { ClusterServiceRoleInstanceEntity roleInstanceEntity = roleInstanceService.getById(ids.get(0)); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertQuotaServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertQuotaServiceImpl.java index 62dba14a..4d8669a1 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertQuotaServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertQuotaServiceImpl.java @@ -17,12 +17,6 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorRef; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.PrometheusActor; import com.datasophon.api.service.AlertGroupService; @@ -37,12 +31,8 @@ import com.datasophon.dao.entity.ClusterAlertQuota; import com.datasophon.dao.enums.QuotaState; import com.datasophon.dao.mapper.ClusterAlertQuotaMapper; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; + +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Arrays; @@ -58,20 +48,35 @@ import java.util.TreeSet; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorRef; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; + @Service("clusterAlertQuotaService") public class ClusterAlertQuotaServiceImpl extends ServiceImpl implements ClusterAlertQuotaService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterAlertQuotaServiceImpl.class); @Autowired AlertGroupService alertGroupService; - + @Override public Result getAlertQuotaList(Integer clusterId, Integer alertGroupId, String quotaName, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; - + LambdaQueryChainWrapper wrapper = this.lambdaQuery() .eq(alertGroupId != null, ClusterAlertQuota::getAlertGroupId, alertGroupId) .like(StringUtils.isNotBlank(quotaName), ClusterAlertQuota::getAlertQuotaName, quotaName); @@ -97,7 +102,7 @@ public Result getAlertQuotaList(Integer clusterId, Integer alertGroupId, String } return Result.success(alertQuotaList).put(Constants.TOTAL, count); } - + private void alertRuleFile(Integer clusterId, Collection alertQuotaList) { HashMap> map = new HashMap<>(); for (ClusterAlertQuota alertQuota : alertQuotaList) { @@ -111,12 +116,12 @@ private void alertRuleFile(Integer clusterId, Collection aler map.put(alertQuota.getServiceCategory(), quotaList); } else { List quotaList = map.get(alertQuota.getServiceCategory()); - + quotaList.add(alertQuota); } alertQuota.setQuotaState(QuotaState.RUNNING); } - + if (alertQuotaList.size() > 0) { logger.info("start alert size is {}", alertQuotaList.size()); this.updateBatchById(alertQuotaList); @@ -130,7 +135,7 @@ private void alertRuleFile(Integer clusterId, Collection aler .collect(Collectors.collectingAndThen(Collectors.toCollection( () -> new TreeSet<>(Comparator.comparing(ClusterAlertQuota::getAlertQuotaName))), ArrayList::new)); - + Generators generators = new Generators(); generators.setFilename(category.toLowerCase() + ".yml"); generators.setConfigFormat("prometheus"); @@ -157,48 +162,48 @@ private void alertRuleFile(Integer clusterId, Collection aler alertConfigCommand.setConfigFileMap(configFileMap); prometheusActor.tell(alertConfigCommand, ActorRef.noSender()); } - + @Override public void start(Integer clusterId, String alertQuotaIds) { List ids = Arrays.asList(alertQuotaIds.split(",")); - if(CollUtil.isEmpty(ids)) { + if (CollUtil.isEmpty(ids)) { return; } - + Collection alertQuotaList = this.listByIds(ids); - + alertRuleFile(clusterId, alertQuotaList); } - + @Transactional(rollbackFor = Exception.class) @Override public void stop(Integer clusterId, String alertQuotaIds) { List ids = Arrays.asList(alertQuotaIds.split(StrUtil.COMMA)); - if(CollUtil.isEmpty(ids)) { + if (CollUtil.isEmpty(ids)) { return; } - + Set categories = new HashSet<>(ids.size()); - //1、修改禁用状态 & 更新 + // 1、修改禁用状态 & 更新 Collection alertQuotas = this.listByIds(ids); alertQuotas.forEach(q -> { q.setQuotaState(QuotaState.STOPPED); categories.add(q.getServiceCategory()); }); this.updateBatchById(alertQuotas); - - //2、查询需要重新生成 alert rule file 的告警指标 + + // 2、查询需要重新生成 alert rule file 的告警指标 Collection clusterAlertQuotas = this.lambdaQuery() .eq(ClusterAlertQuota::getQuotaState, QuotaState.RUNNING) .in(ClusterAlertQuota::getServiceCategory, categories) .list(); - if(CollUtil.isEmpty(clusterAlertQuotas)) { + if (CollUtil.isEmpty(clusterAlertQuotas)) { return; } - + alertRuleFile(clusterId, clusterAlertQuotas); } - + @Override public void saveAlertQuota(ClusterAlertQuota clusterAlertQuota) { clusterAlertQuota.setQuotaState(QuotaState.STOPPED); @@ -207,7 +212,7 @@ public void saveAlertQuota(ClusterAlertQuota clusterAlertQuota) { clusterAlertQuota.setServiceCategory(alertGroupEntity.getAlertGroupCategory()); this.save(clusterAlertQuota); } - + @Override public List listAlertQuotaByServiceName(String serviceName) { return this.list(new QueryWrapper().eq(Constants.SERVICE_CATEGORY, serviceName)); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertRuleServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertRuleServiceImpl.java index 2abf6115..169698c8 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertRuleServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterAlertRuleServiceImpl.java @@ -17,15 +17,17 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterAlertRuleService; import com.datasophon.dao.entity.ClusterAlertRule; import com.datasophon.dao.mapper.ClusterAlertRuleMapper; + import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterAlertRuleService") public class ClusterAlertRuleServiceImpl extends ServiceImpl implements ClusterAlertRuleService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterGroupServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterGroupServiceImpl.java index 6ad79d77..d842f7c8 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterGroupServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterGroupServiceImpl.java @@ -17,17 +17,12 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorRef; -import akka.pattern.Patterns; -import akka.util.Timeout; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.exceptions.ServiceException; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.service.ClusterGroupService; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterUserGroupService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.utils.ProcessUtils; import com.datasophon.common.Constants; import com.datasophon.common.command.remote.CreateUnixGroupCommand; @@ -38,12 +33,9 @@ import com.datasophon.dao.entity.ClusterHostDO; import com.datasophon.dao.entity.ClusterUser; import com.datasophon.dao.mapper.ClusterGroupMapper; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -53,20 +45,33 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorRef; +import akka.pattern.Patterns; +import akka.util.Timeout; + @Service("clusterGroupService") @Transactional public class ClusterGroupServiceImpl extends ServiceImpl implements - ClusterGroupService { - + ClusterGroupService { + private static final Logger logger = LoggerFactory.getLogger(ClusterGroupServiceImpl.class); - + @Autowired private ClusterHostService hostService; - + @Autowired private ClusterUserGroupService userGroupService; - + @Override public Result saveClusterGroup(Integer clusterId, String groupName) { if (hasRepeatGroupName(clusterId, groupName)) { @@ -76,7 +81,7 @@ public Result saveClusterGroup(Integer clusterId, String groupName) { clusterGroup.setClusterId(clusterId); clusterGroup.setGroupName(groupName); this.save(clusterGroup); - + List hostList = hostService.getHostListByClusterId(clusterId); for (ClusterHostDO clusterHost : hostList) { ActorRef unixGroupActor = ActorUtils.getRemoteActor(clusterHost.getHostname(), "unixGroupActor"); @@ -99,10 +104,10 @@ public Result saveClusterGroup(Integer clusterId, String groupName) { "create unix group " + groupName + " failed at " + clusterHost.getHostname()); } } - + return Result.success(); } - + private boolean hasRepeatGroupName(Integer clusterId, String groupName) { List list = this.list(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId) @@ -112,7 +117,7 @@ private boolean hasRepeatGroupName(Integer clusterId, String groupName) { } return false; } - + @Override public void refreshUserGroupToHost(Integer clusterId) { List hostList = hostService.getHostListByClusterId(clusterId); @@ -121,7 +126,7 @@ public void refreshUserGroupToHost(Integer clusterId) { ProcessUtils.syncUserGroupToHosts(hostList, clusterGroup.getGroupName(), "groupadd"); } } - + @Override public Result deleteUserGroup(Integer id) { ClusterGroup clusterGroup = this.getById(id); @@ -151,7 +156,7 @@ public Result deleteUserGroup(Integer id) { } return Result.success(); } - + @Override public Result listPage(String groupName, Integer clusterId, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; @@ -167,23 +172,23 @@ public Result listPage(String groupName, Integer clusterId, Integer page, Intege clusterGroup.setClusterUsers(clusterUsers); } } - int total = this.count(new QueryWrapper(). - like(StringUtils.isNotBlank(groupName), Constants.GROUP_NAME, groupName) + int total = this.count(new QueryWrapper() + .like(StringUtils.isNotBlank(groupName), Constants.GROUP_NAME, groupName) .eq(Constants.CLUSTER_ID, clusterId)); return Result.success(list).put(Constants.TOTAL, total); } - + @Override public List listAllUserGroup(Integer clusterId) { return this.lambdaQuery().eq(ClusterGroup::getClusterId, clusterId).list(); } - + @Override public void createUnixGroupOnHost(String hostname, String groupName) { ActorRef unixGroupActor = ActorUtils.getRemoteActor(hostname, "unixGroupActor"); createUnixGroup(hostname, unixGroupActor, groupName); } - + private void createUnixGroup(String hostname, ActorRef unixGroupActor, String groupName) { CreateUnixGroupCommand createUnixGroupCommand = new CreateUnixGroupCommand(); createUnixGroupCommand.setGroupName(groupName); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterInfoServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterInfoServiceImpl.java index e9641e6d..6f1eb2fe 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterInfoServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterInfoServiceImpl.java @@ -17,15 +17,21 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorRef; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.load.ConfigBean; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.ClusterActor; -import com.datasophon.api.service.*; +import com.datasophon.api.service.AlertGroupService; +import com.datasophon.api.service.ClusterAlertGroupMapService; +import com.datasophon.api.service.ClusterInfoService; +import com.datasophon.api.service.ClusterNodeLabelService; +import com.datasophon.api.service.ClusterQueueCapacityService; +import com.datasophon.api.service.ClusterRackService; +import com.datasophon.api.service.ClusterRoleUserService; +import com.datasophon.api.service.ClusterServiceInstanceService; +import com.datasophon.api.service.ClusterYarnSchedulerService; +import com.datasophon.api.service.FrameServiceService; import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.utils.PackageUtils; import com.datasophon.api.utils.ProcessUtils; @@ -35,68 +41,79 @@ import com.datasophon.common.command.ClusterCommand; import com.datasophon.common.enums.ClusterCommandType; import com.datasophon.common.utils.Result; -import com.datasophon.dao.entity.*; +import com.datasophon.dao.entity.AlertGroupEntity; +import com.datasophon.dao.entity.ClusterAlertGroupMap; +import com.datasophon.dao.entity.ClusterInfoEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceEntity; +import com.datasophon.dao.entity.FrameServiceEntity; +import com.datasophon.dao.entity.UserInfoEntity; import com.datasophon.dao.enums.ClusterState; import com.datasophon.dao.mapper.ClusterInfoMapper; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Objects; +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorRef; + @Slf4j @Service("clusterInfoService") @Transactional public class ClusterInfoServiceImpl extends ServiceImpl implements - ClusterInfoService { - - + ClusterInfoService { + @Autowired private ClusterInfoMapper clusterInfoMapper; - + @Autowired private ClusterRoleUserService clusterUserService; - + @Autowired private AlertGroupService alertGroupService; - + @Autowired private ClusterAlertGroupMapService groupMapService; - + @Autowired private ConfigBean configBean; - + @Autowired private FrameServiceService frameServiceService; - + @Autowired private ClusterHostService clusterHostService; - + @Autowired private ClusterYarnSchedulerService yarnSchedulerService; - + @Autowired private ClusterNodeLabelService nodeLabelService; - + @Autowired private ClusterQueueCapacityService queueCapacityService; - + @Autowired private ClusterRackService rackService; - + @Autowired private ClusterServiceInstanceService clusterServiceInstanceService; - + @Override public ClusterInfoEntity getClusterByClusterCode(String clusterCode) { return clusterInfoMapper.getClusterByClusterCode(clusterCode); } - + @Override public Result saveCluster(ClusterInfoEntity clusterInfo) { List list = this @@ -116,19 +133,19 @@ public Result saveCluster(ClusterInfoEntity clusterInfo) { groupMapService.save(alertGroupMap); } // ProcessUtils.createServiceActor(clusterInfo); - + yarnSchedulerService.createDefaultYarnScheduler(clusterInfo.getId()); - + nodeLabelService.createDefaultNodeLabel(clusterInfo.getId()); - + queueCapacityService.createDefaultQueue(clusterInfo.getId()); - + rackService.createDefaultRack(clusterInfo.getId()); - + putClusterVariable(clusterInfo); return Result.success(); } - + private void putClusterVariable(ClusterInfoEntity clusterInfo) { HashMap globalVariables = new HashMap<>(); List frameServiceList = @@ -142,10 +159,10 @@ private void putClusterVariable(ClusterInfoEntity clusterInfo) { globalVariables.put("${apiPort}", configBean.getServerPort()); globalVariables.put("${HADOOP_HOME}", Constants.INSTALL_PATH + Constants.SLASH + PackageUtils.getServiceDcPackageName(clusterInfo.getClusterFrame(), "HDFS")); - + GlobalVariables.put(clusterInfo.getId(), globalVariables); } - + @Override public Result getClusterList() { List list = this.list(); @@ -157,14 +174,14 @@ public Result getClusterList() { } return Result.success(list); } - + @Override public Result runningClusterList() { List list = this.list(new QueryWrapper().eq(Constants.CLUSTER_STATE, ClusterState.RUNNING)); return Result.success(list); } - + @Override public Result updateClusterState(Integer clusterId, Integer clusterState) { ClusterInfoEntity clusterInfo = this.getById(clusterId); @@ -177,12 +194,12 @@ public Result updateClusterState(Integer clusterId, Integer clusterState) { return Result.error("未知状态"); } } - + @Override public List getClusterByFrameCode(String frameCode) { return this.list(new QueryWrapper().eq(Constants.CLUSTER_FRAME, frameCode)); } - + @Override public Result updateCluster(ClusterInfoEntity clusterInfo) { // 集群编码判重 @@ -201,19 +218,20 @@ public Result updateCluster(ClusterInfoEntity clusterInfo) { this.updateById(clusterInfo); return Result.success(); } - + @Override public void deleteCluster(List ids) { Integer id = ids.get(0); ClusterInfoEntity clusterInfo = this.getById(id); - + if (ClusterState.STOP.equals(clusterInfo.getClusterState())) { List serviceInstanceList = clusterServiceInstanceService.listAll(id); - if (serviceInstanceList.stream().noneMatch(instance -> clusterServiceInstanceService.hasRunningRoleInstance(instance.getId()))) { + if (serviceInstanceList.stream() + .noneMatch(instance -> clusterServiceInstanceService.hasRunningRoleInstance(instance.getId()))) { ActorUtils.getLocalActor( ClusterActor.class, "clusterActor") .tell(new ClusterCommand(ClusterCommandType.DELETE, id), ActorRef.noSender()); - + this.updateClusterState(id, ClusterState.DELETING.getValue()); } } @@ -222,9 +240,7 @@ public void deleteCluster(List ids) { // delete host clusterHostService.removeHostByClusterId(id); } - - - + } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterKerberosServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterKerberosServiceImpl.java index 7c0c06d1..64f36ff2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterKerberosServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterKerberosServiceImpl.java @@ -19,13 +19,21 @@ package com.datasophon.api.service.impl; -import cn.hutool.core.io.FileUtil; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.service.ClusterKerberosService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; import com.datasophon.common.Constants; import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.ShellUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,33 +41,28 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Map; +import cn.hutool.core.io.FileUtil; @Service("clusterKerberosService") @Transactional public class ClusterKerberosServiceImpl implements ClusterKerberosService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterKerberosServiceImpl.class); - + private static final String SSHUSER = "SSHUSER"; - + private static final String KEYTAB_PATH = "/etc/security/keytab"; - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Override public void downloadKeytab( - Integer clusterId, - String principal, - String keytabName, - String hostname, - HttpServletResponse response) throws IOException { + Integer clusterId, + String principal, + String keytabName, + String hostname, + HttpServletResponse response) throws IOException { String keytabFilePath = KEYTAB_PATH + Constants.SLASH + hostname + Constants.SLASH + keytabName; File file = new File(keytabFilePath); @@ -84,18 +87,18 @@ public void downloadKeytab( out.close(); } } - + @Override public void uploadKeytab(MultipartFile file, String hostname, String keytabFileName) throws IOException { String keytabFilePath = KEYTAB_PATH + Constants.SLASH + hostname + Constants.SLASH + keytabFileName; file.transferTo(new File(keytabFilePath)); } - + private void generateKeytabFile( - Integer clusterId, - String keytabFilePath, - String principal) { + Integer clusterId, + String keytabFilePath, + String principal) { Map globalVariables = GlobalVariables.get(clusterId); String kadminPrincipal = globalVariables.get("${kadminPrincipal}"); String kadminPassword = globalVariables.get("${kadminPassword}"); @@ -103,17 +106,19 @@ private void generateKeytabFile( ExecResult execResult = ShellUtils.exceShell(listPrinc); String execOut = execResult.getExecOut(); if (!execOut.contains(principal)) { - String addprinc = "kadmin -p" + kadminPrincipal + " -w" + kadminPassword + " -q \"addprinc -randkey " + principal + "\""; + String addprinc = "kadmin -p" + kadminPrincipal + " -w" + kadminPassword + " -q \"addprinc -randkey " + + principal + "\""; logger.info("add principal cmd is : {}", addprinc); ShellUtils.exceShell(addprinc); } if (!FileUtil.exist(keytabFilePath)) { FileUtil.mkParentDirs(keytabFilePath); } - String keytabCmd = "kadmin -p" + kadminPrincipal + " -w" + kadminPassword + " -q \"xst -k " + keytabFilePath + " " - + principal + "\""; + String keytabCmd = + "kadmin -p" + kadminPrincipal + " -w" + kadminPassword + " -q \"xst -k " + keytabFilePath + " " + + principal + "\""; logger.info("generate keytab file cmd is : {}", keytabCmd); ShellUtils.exceShell(keytabCmd); - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterNodeLabelServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterNodeLabelServiceImpl.java index c948aaff..bd406ef0 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterNodeLabelServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterNodeLabelServiceImpl.java @@ -17,18 +17,13 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.exceptions.BusinessException; import com.datasophon.api.master.ActorUtils; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterNodeLabelService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.utils.PackageUtils; import com.datasophon.common.Constants; import com.datasophon.common.command.ExecuteCmdCommand; @@ -39,11 +34,7 @@ import com.datasophon.dao.entity.ClusterNodeLabelEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.mapper.ClusterNodeLabelMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -54,23 +45,36 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; + @Service("clusterNodeLabelService") @Transactional public class ClusterNodeLabelServiceImpl extends ServiceImpl implements ClusterNodeLabelService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterNodeLabelServiceImpl.class); - + @Autowired private ClusterHostService hostService; - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Autowired private ClusterInfoService clusterInfoService; - + @Override public Result saveNodeLabel(Integer clusterId, String nodeLabel) { if (repeatNodeLable(clusterId, nodeLabel)) { @@ -87,7 +91,7 @@ public Result saveNodeLabel(Integer clusterId, String nodeLabel) { } return Result.success(); } - + private boolean refreshToYarn(Integer clusterId, String type, String nodeLabel) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); List roleList = @@ -120,11 +124,11 @@ private boolean refreshToYarn(Integer clusterId, String type, String nodeLabel) } return true; } - + @Override public Result deleteNodeLabel(Integer nodeLabelId) { ClusterNodeLabelEntity nodeLabelEntity = this.getById(nodeLabelId); - + if (nodeLabelInUse(nodeLabelEntity.getNodeLabel())) { return Result.error(Status.NODE_LABEL_IS_USING.getMsg()); } @@ -135,13 +139,13 @@ public Result deleteNodeLabel(Integer nodeLabelId) { } return Result.success(); } - + @Override public Result assignNodeLabel(Integer nodeLabelId, String hostIds) { ClusterNodeLabelEntity nodeLabelEntity = this.getById(nodeLabelId); List ids = Arrays.asList(hostIds.split(",")); hostService.updateBatchNodeLabel(ids, nodeLabelEntity.getNodeLabel()); - + List list = hostService.getHostListByIds(ids); String assignNodeLabel = list.stream().map(e -> e.getHostname() + "=" + nodeLabelEntity.getNodeLabel()) .collect(Collectors.joining(" ")); @@ -153,12 +157,12 @@ public Result assignNodeLabel(Integer nodeLabelId, String hostIds) { } return Result.success(); } - + @Override public List queryClusterNodeLabel(Integer clusterId) { return this.list(new QueryWrapper().eq(Constants.CLUSTER_ID, clusterId)); } - + @Override public void createDefaultNodeLabel(Integer clusterId) { ClusterNodeLabelEntity nodeLabelEntity = new ClusterNodeLabelEntity(); @@ -166,7 +170,7 @@ public void createDefaultNodeLabel(Integer clusterId) { nodeLabelEntity.setClusterId(clusterId); this.save(nodeLabelEntity); } - + private boolean nodeLabelInUse(String nodeLabel) { List list = hostService.list(new QueryWrapper() .eq(Constants.NODE_LABEL, nodeLabel)); @@ -175,7 +179,7 @@ private boolean nodeLabelInUse(String nodeLabel) { } return false; } - + private boolean repeatNodeLable(Integer clusterId, String nodeLabel) { List list = this.list(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId) diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterQueueCapacityServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterQueueCapacityServiceImpl.java index 8f60a7a1..b32f222c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterQueueCapacityServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterQueueCapacityServiceImpl.java @@ -17,10 +17,6 @@ package com.datasophon.api.service.impl; -import cn.hutool.core.bean.BeanUtil; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.service.ClusterQueueCapacityService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; @@ -37,26 +33,34 @@ import com.datasophon.dao.mapper.ClusterQueueCapacityMapper; import com.datasophon.dao.model.ClusterQueueCapacityList; import com.datasophon.dao.model.Links; -import org.apache.commons.lang.StringUtils; + +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import cn.hutool.core.bean.BeanUtil; @Service("clusterQueueCapacityService") public class ClusterQueueCapacityServiceImpl extends ServiceImpl implements ClusterQueueCapacityService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterQueueCapacityServiceImpl.class); - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Override public Result refreshToYarn(Integer clusterId) throws Exception { List list = this.list(new QueryWrapper() @@ -64,7 +68,7 @@ public Result refreshToYarn(Integer clusterId) throws Exception { ClusterInfoEntity clusterInfo = ProcessUtils.getClusterInfo(clusterId); List roleList = roleInstanceService.getServiceRoleInstanceListByClusterIdAndRoleName(clusterId, "ResourceManager"); - + // build configfilemap HashMap> configFileMap = new HashMap<>(); Generators generators = new Generators(); @@ -72,24 +76,24 @@ public Result refreshToYarn(Integer clusterId) throws Exception { generators.setOutputDirectory("etc/hadoop"); generators.setConfigFormat("custom"); generators.setTemplateName("capacity-scheduler.ftl"); - + ArrayList serviceConfigs = new ArrayList<>(); ServiceConfig config = new ServiceConfig(); ArrayList queueList = new ArrayList<>(); - + for (ClusterQueueCapacity clusterYarnQueue : list) { JSONObject queue = new JSONObject(); BeanUtil.copyProperties(clusterYarnQueue, queue, false); queueList.add(queue); } - + config.setName("queueList"); config.setValue(queueList); config.setConfigType("map"); config.setRequired(true); - + serviceConfigs.add(config); - + configFileMap.put(generators, serviceConfigs); String hostname = ""; for (ClusterServiceRoleInstanceEntity roleInstanceEntity : roleList) { @@ -110,7 +114,7 @@ public Result refreshToYarn(Integer clusterId) throws Exception { } return Result.success(); } - + @Override public void createDefaultQueue(Integer clusterId) { ClusterQueueCapacity queueCapacity = new ClusterQueueCapacity(); @@ -122,16 +126,16 @@ public void createDefaultQueue(Integer clusterId) { queueCapacity.setParent("root"); this.save(queueCapacity); } - + @Override public Result listCapacityQueue(Integer clusterId) { List list = this.list(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId)); - + ClusterQueueCapacityList clusterQueueCapacityList = new ClusterQueueCapacityList(); clusterQueueCapacityList.setRootId("root"); clusterQueueCapacityList.setNodes(list); - + ArrayList linksList = new ArrayList<>(); for (ClusterQueueCapacity clusterQueueCapacity : list) { Links links = new Links(); @@ -142,5 +146,5 @@ public Result listCapacityQueue(Integer clusterId) { clusterQueueCapacityList.setLinks(linksList); return Result.success(clusterQueueCapacityList); } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRackServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRackServiceImpl.java index 85ae445a..45be0004 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRackServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRackServiceImpl.java @@ -17,32 +17,34 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterRackService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.common.Constants; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterHostDO; import com.datasophon.dao.entity.ClusterRack; import com.datasophon.dao.mapper.ClusterRackMapper; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service("clusterRackService") public class ClusterRackServiceImpl extends ServiceImpl implements ClusterRackService { - + @Autowired private ClusterHostService hostService; - + @Override public List queryClusterRack(Integer clusterId) { return this.list(new QueryWrapper().eq(Constants.CLUSTER_ID, clusterId)); } - + @Override public void saveRack(Integer clusterId, String rack) { ClusterRack clusterRack = new ClusterRack(); @@ -50,7 +52,7 @@ public void saveRack(Integer clusterId, String rack) { clusterRack.setClusterId(clusterId); this.save(clusterRack); } - + @Override public Result deleteRack(Integer rackId) { ClusterRack clusterRack = this.getById(rackId); @@ -60,7 +62,7 @@ public Result deleteRack(Integer rackId) { this.removeById(rackId); return Result.success(); } - + @Override public void createDefaultRack(Integer clusterId) { ClusterRack clusterRack = new ClusterRack(); @@ -68,7 +70,7 @@ public void createDefaultRack(Integer clusterId) { clusterRack.setClusterId(clusterId); this.save(clusterRack); } - + private boolean rackInUse(ClusterRack clusterRack) { List list = hostService.getClusterHostByRack(clusterRack.getClusterId(), clusterRack.getRack()); @@ -77,5 +79,5 @@ private boolean rackInUse(ClusterRack clusterRack) { } return false; } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRoleUserServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRoleUserServiceImpl.java index 9aab4cee..efd531eb 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRoleUserServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterRoleUserServiceImpl.java @@ -17,9 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterRoleUserService; import com.datasophon.common.Constants; import com.datasophon.common.utils.Result; @@ -27,21 +24,26 @@ import com.datasophon.dao.entity.UserInfoEntity; import com.datasophon.dao.enums.UserType; import com.datasophon.dao.mapper.ClusterRoleUserMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterRoleUserService") public class ClusterRoleUserServiceImpl extends ServiceImpl implements - ClusterRoleUserService { - + ClusterRoleUserService { + @Autowired private ClusterRoleUserMapper clusterRoleUserMapper; - + @Override public boolean isClusterManager(Integer userId, String clusterId) { List list = this.list(new QueryWrapper() @@ -52,7 +54,7 @@ public boolean isClusterManager(Integer userId, String clusterId) { } return false; } - + @Override public Result saveClusterManager(Integer clusterId, String userIds) { // 首先删除原有管理员 @@ -73,9 +75,9 @@ public Result saveClusterManager(Integer clusterId, String userIds) { this.saveBatch(list); return Result.success(); } - + @Override public List getAllClusterManagerByClusterId(Integer clusterId) { return clusterRoleUserMapper.getAllClusterManagerByClusterId(clusterId); } -} \ No newline at end of file +} diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostCommandServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostCommandServiceImpl.java index 53d15cba..63d42a69 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostCommandServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostCommandServiceImpl.java @@ -17,11 +17,6 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterServiceCommandHostCommandService; @@ -37,10 +32,7 @@ import com.datasophon.dao.entity.ClusterServiceCommandHostCommandEntity; import com.datasophon.dao.enums.CommandState; import com.datasophon.dao.mapper.ClusterServiceCommandHostCommandMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -49,30 +41,42 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; + @Service("clusterServiceCommandHostCommandService") public class ClusterServiceCommandHostCommandServiceImpl extends ServiceImpl implements ClusterServiceCommandHostCommandService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterServiceCommandHostCommandServiceImpl.class); - + @Autowired ClusterServiceCommandHostCommandMapper hostCommandMapper; - + @Autowired FrameServiceRoleService frameServiceRoleService; - + @Autowired FrameServiceService frameService; - + @Autowired ClusterInfoService clusterInfoService; - + @Autowired ClusterServiceCommandService commandService; - + @Override public Result getHostCommandList(String hostname, String commandHostId, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; @@ -88,50 +92,50 @@ public Result getHostCommandList(String hostname, String commandHostId, Integer } return Result.success(list).put(Constants.TOTAL, total); } - + @Override public List getHostCommandListByCommandId(String commandId) { return this.lambdaQuery().eq(ClusterServiceCommandHostCommandEntity::getCommandId, commandId).list(); } - + @Override public ClusterServiceCommandHostCommandEntity getByHostCommandId(String hostCommandId) { return this.getOne(new QueryWrapper().eq(Constants.HOST_COMMAND_ID, hostCommandId)); } - + @Override public void updateByHostCommandId(ClusterServiceCommandHostCommandEntity hostCommand) { this.update(hostCommand, new QueryWrapper() .eq(Constants.HOST_COMMAND_ID, hostCommand.getHostCommandId())); } - + @Override public Integer getHostCommandSizeByHostnameAndCommandHostId(String hostname, String commandHostId) { int size = this.count(new QueryWrapper() .eq(Constants.HOSTNAME, hostname).eq(Constants.COMMAND_HOST_ID, commandHostId)); return size; } - + @Override public Integer getHostCommandTotalProgressByHostnameAndCommandHostId(String hostname, String commandHostId) { return hostCommandMapper.getHostCommandTotalProgressByHostnameAndCommandHostId(hostname, commandHostId); } - + @Override public Result getHostCommandLog(Integer clusterId, String hostCommandId) throws Exception { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); - + ClusterServiceCommandHostCommandEntity hostCommand = this.getOne(new QueryWrapper().eq(Constants.HOST_COMMAND_ID, hostCommandId)); - + ClusterServiceCommandEntity commandEntity = commandService.getCommandById(hostCommand.getCommandId()); - + String serviceName = commandEntity.getServiceName(); String serviceRoleName = hostCommand.getServiceRoleName(); - String logFile = String.format("%s/%s/%s.log","logs",serviceName,serviceRoleName); - + String logFile = String.format("%s/%s/%s.log", "logs", serviceName, serviceRoleName); + GetLogCommand command = new GetLogCommand(); command.setLogFile(logFile); command.setDecompressPackageName("datasophon-worker"); @@ -146,7 +150,7 @@ public Result getHostCommandLog(Integer clusterId, String hostCommandId) throws } return Result.success(); } - + @Override public List findFailedHostCommand(String hostname, String commandHostId) { return this.list(new QueryWrapper() @@ -154,7 +158,7 @@ public List findFailedHostCommand(String .eq(Constants.COMMAND_HOST_ID, commandHostId) .eq(Constants.COMMAND_STATE, CommandState.FAILED)); } - + @Override public List findCanceledHostCommand(String hostname, String commandHostId) { return this.list(new QueryWrapper() diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostServiceImpl.java index b84df8d7..add80392 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandHostServiceImpl.java @@ -17,8 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterServiceCommandHostCommandService; import com.datasophon.api.service.ClusterServiceCommandHostService; import com.datasophon.common.Constants; @@ -26,10 +24,14 @@ import com.datasophon.dao.entity.ClusterServiceCommandHostEntity; import com.datasophon.dao.enums.CommandState; import com.datasophon.dao.mapper.ClusterServiceCommandHostMapper; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; +import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service("clusterServiceCommandHostService") public class ClusterServiceCommandHostServiceImpl @@ -37,17 +39,17 @@ public class ClusterServiceCommandHostServiceImpl ServiceImpl implements ClusterServiceCommandHostService { - + @Autowired private ClusterServiceCommandHostCommandService hostCommandService; - + @Autowired private ClusterServiceCommandHostMapper hostMapper; - + @Override public Result getCommandHostList(Integer clusterId, String commandId, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; - + LambdaQueryChainWrapper wrapper = this.lambdaQuery() .eq(ClusterServiceCommandHostEntity::getCommandId, commandId); int total = wrapper.count(); @@ -58,20 +60,20 @@ public Result getCommandHostList(Integer clusterId, String commandId, Integer pa for (ClusterServiceCommandHostEntity commandHostEntity : list) { commandHostEntity.setCommandStateCode(commandHostEntity.getCommandState().getValue()); } - + return Result.success(list).put(Constants.TOTAL, total); } - + @Override public Integer getCommandHostSizeByCommandId(String commandId) { return this.lambdaQuery().eq(ClusterServiceCommandHostEntity::getCommandId, commandId).count(); } - + @Override public Integer getCommandHostTotalProgressByCommandId(String commandId) { return hostMapper.getCommandHostTotalProgressByCommandId(commandId); } - + @Override public List findFailedCommandHost(String commandId) { return this.lambdaQuery() @@ -79,7 +81,7 @@ public List findFailedCommandHost(String comman .eq(ClusterServiceCommandHostEntity::getCommandState, CommandState.FAILED) .list(); } - + @Override public List findCanceledCommandHost(String commandId) { return this.lambdaQuery() @@ -87,5 +89,5 @@ public List findCanceledCommandHost(String comm .eq(ClusterServiceCommandHostEntity::getCommandState, CommandState.CANCEL) .list(); } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandServiceImpl.java index cd1e40d6..e6612bb4 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceCommandServiceImpl.java @@ -17,13 +17,6 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorRef; -import cn.hutool.core.date.BetweenFormatter; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.EnumUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.DAGBuildActor; @@ -52,11 +45,6 @@ import com.datasophon.dao.entity.FrameServiceEntity; import com.datasophon.dao.entity.FrameServiceRoleEntity; import com.datasophon.dao.mapper.ClusterServiceCommandMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Arrays; @@ -66,70 +54,86 @@ import java.util.Map; import java.util.Objects; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorRef; + +import cn.hutool.core.date.BetweenFormatter; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.EnumUtil; + @Service("clusterServiceCommandService") public class ClusterServiceCommandServiceImpl extends - ServiceImpl + ServiceImpl implements - ClusterServiceCommandService { - + ClusterServiceCommandService { + private static final Logger logger = LoggerFactory.getLogger(ClusterServiceCommandServiceImpl.class); - + @Autowired private ClusterInfoService clusterInfoService; - + @Autowired private ClusterServiceCommandHostService commandHostService; - + @Autowired private ClusterServiceCommandHostCommandService hostCommandService; - + @Autowired private FrameServiceService frameServiceService; - + @Autowired private FrameServiceRoleService frameServiceRoleService; - + @Autowired private ClusterServiceCommandService commandService; - + @Autowired private ClusterHostService hostService; - + @Autowired private ClusterServiceInstanceService serviceInstanceService; - + @Autowired private ClusterServiceInstanceConfigService serviceInstanceConfigService; - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Override @Transactional public Result generateCommand(Integer clusterId, CommandType commandType, List serviceNames) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); - + List list = new ArrayList<>(); List commandHostList = new ArrayList<>(); List hostCommandList = new ArrayList<>(); List commandIds = new ArrayList(); - + Map> serviceRoleHostMap = (Map>) CacheUtils .get(clusterInfo.getClusterCode() + Constants.UNDERLINE + Constants.SERVICE_ROLE_HOST_MAPPING); - + for (String serviceName : serviceNames) { // 1、生成操作指令 ClusterServiceInstanceEntity serviceInstance = serviceInstanceService.getServiceInstanceByClusterIdAndServiceName(clusterId, serviceName); - + ClusterServiceCommandEntity commandEntity = ProcessUtils.generateCommandEntity(clusterId, commandType, serviceName); commandEntity.setServiceInstanceId(serviceInstance.getId()); list.add(commandEntity); String commandId = commandEntity.getCommandId(); commandIds.add(commandId); - + // 查询服务的服务角色 FrameServiceEntity frameService = frameServiceService.getServiceByFrameCodeAndServiceName(clusterInfo.getClusterFrame(), serviceName); @@ -173,7 +177,7 @@ public Result generateCommand(Integer clusterId, CommandType commandType, List map = new HashMap<>(); for (ClusterServiceRoleInstanceEntity roleInstance : roleInstanceList) { ClusterServiceCommandHostEntity commandHost; @@ -257,7 +261,7 @@ public Result generateServiceCommand(Integer clusterId, CommandType commandType, commandService.saveBatch(list); commandHostService.saveBatch(commandHostList); hostCommandService.saveBatch(hostCommandList); - + // 通知commandActor执行命令 ActorRef dagBuildActor = ActorUtils.getLocalActor(DAGBuildActor.class, ActorUtils.getActorRefName(DAGBuildActor.class)); @@ -265,7 +269,7 @@ public Result generateServiceCommand(Integer clusterId, CommandType commandType, } return Result.success(String.join(",", commandIds)); } - + @Override public Result generateServiceRoleCommands(Integer clusterId, CommandType commandType, Map> instanceIdMap) { @@ -275,7 +279,7 @@ public Result generateServiceRoleCommands(Integer clusterId, CommandType command } return result; } - + @Override public Result generateServiceRoleCommand(Integer clusterId, CommandType commandType, Integer serviceInstanceId, List serviceRoleInstanceIds) { @@ -283,7 +287,7 @@ public Result generateServiceRoleCommand(Integer clusterId, CommandType commandT List commandHostList = new ArrayList<>(); List hostCommandList = new ArrayList<>(); List commandIds = new ArrayList<>(); - + ClusterServiceInstanceEntity serviceInstance = serviceInstanceService.getById(serviceInstanceId); ClusterServiceCommandEntity commandEntity = ProcessUtils.generateCommandEntity(clusterId, commandType, serviceInstance.getServiceName()); @@ -296,7 +300,7 @@ public Result generateServiceRoleCommand(Integer clusterId, CommandType commandT for (String serviceRoleInstanceId : serviceRoleInstanceIds) { int id = Integer.parseInt(serviceRoleInstanceId); ClusterServiceRoleInstanceEntity roleInstance = roleInstanceService.getById(id); - + ClusterServiceCommandHostEntity commandHost; if (map.containsKey(roleInstance.getHostname())) { commandHost = map.get(roleInstance.getHostname()); @@ -312,14 +316,14 @@ public Result generateServiceRoleCommand(Integer clusterId, CommandType commandT commandService.saveBatch(list); commandHostService.saveBatch(commandHostList); hostCommandService.saveBatch(hostCommandList); - + // 通知commandActor执行命令 ActorRef dagBuildActor = ActorUtils.getLocalActor(DAGBuildActor.class, ActorUtils.getActorRefName(DAGBuildActor.class)); dagBuildActor.tell(new StartExecuteCommandCommand(commandIds, clusterId, commandType), ActorRef.noSender()); return Result.success(String.join(",", commandIds)); } - + @Override public void startExecuteCommand(Integer clusterId, String commandType, String commandIds) { List list = Arrays.asList(commandIds.split(",")); @@ -329,13 +333,13 @@ public void startExecuteCommand(Integer clusterId, String commandType, String co ActorUtils.getLocalActor(DAGBuildActor.class, ActorUtils.getActorRefName(DAGBuildActor.class)); dagBuildActor.tell(new StartExecuteCommandCommand(list, clusterId, command), ActorRef.noSender()); } - + @Override public void cancelCommand(String commandId) { // command , command host, host command状态置为取消 - + } - + @Override public ClusterServiceCommandEntity getLastRestartCommand(Integer serviceInstanceId) { return this.getOne( @@ -344,7 +348,7 @@ public ClusterServiceCommandEntity getLastRestartCommand(Integer serviceInstance .eq(Constants.COMMAND_TYPE, CommandType.INSTALL_SERVICE.getValue()) .orderByDesc(Constants.CREATE_TIME).last("limit 1")); } - + @Override public ClusterServiceCommandEntity getCommandById(String commandId) { return this.getOne( diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceDashboardServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceDashboardServiceImpl.java index 8250849f..bb03db5d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceDashboardServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceDashboardServiceImpl.java @@ -17,8 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.service.ClusterServiceDashboardService; import com.datasophon.common.Constants; @@ -26,10 +24,14 @@ import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceDashboard; import com.datasophon.dao.mapper.ClusterServiceDashboardMapper; + +import java.util.Map; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Map; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service("clusterServiceDashboardService") public class ClusterServiceDashboardServiceImpl @@ -37,10 +39,10 @@ public class ClusterServiceDashboardServiceImpl ServiceImpl implements ClusterServiceDashboardService { - + @Autowired ClusterServiceDashboardService dashboardService; - + @Override public Result getDashboardUrl(Integer clusterId) { Map globalVariables = GlobalVariables.get(clusterId); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceConfigServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceConfigServiceImpl.java index c27e48a6..66f5da1e 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceConfigServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceConfigServiceImpl.java @@ -17,9 +17,6 @@ package com.datasophon.api.service.impl; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterServiceInstanceConfigService; import com.datasophon.api.service.ClusterServiceRoleGroupConfigService; import com.datasophon.common.Constants; @@ -28,23 +25,28 @@ import com.datasophon.dao.entity.ClusterServiceInstanceConfigEntity; import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; import com.datasophon.dao.mapper.ClusterServiceInstanceConfigMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterServiceInstanceConfigService") public class ClusterServiceInstanceConfigServiceImpl extends ServiceImpl implements ClusterServiceInstanceConfigService { - + @Autowired private ClusterServiceRoleGroupConfigService roleGroupConfigService; - + @Override public Result getServiceInstanceConfig(Integer serviceInstanceId, Integer version, Integer roleGroupId, Integer page, Integer pageSize) { @@ -57,7 +59,7 @@ public Result getServiceInstanceConfig(Integer serviceInstanceId, Integer versio } return Result.success(); } - + @Override public ClusterServiceInstanceConfigEntity getServiceConfigByServiceId(Integer id) { return this.lambdaQuery() @@ -66,10 +68,10 @@ public ClusterServiceInstanceConfigEntity getServiceConfigByServiceId(Integer id .last("limit 1") .one(); } - + @Override public Result getConfigVersion(Integer serviceInstanceId, Integer roleGroupId) { - + List list = roleGroupConfigService.list(new QueryWrapper() .eq(Constants.ROLE_GROUP_ID, roleGroupId) diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceRoleGroupServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceRoleGroupServiceImpl.java index c9dbfca6..a11e5671 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceRoleGroupServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceRoleGroupServiceImpl.java @@ -19,8 +19,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.service.ClusterServiceInstanceRoleGroupService; import com.datasophon.api.service.ClusterServiceInstanceService; @@ -34,33 +32,37 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.NeedRestart; import com.datasophon.dao.mapper.ClusterServiceInstanceRoleGroupMapper; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterServiceInstanceRoleGroupService") public class ClusterServiceInstanceRoleGroupServiceImpl extends ServiceImpl implements ClusterServiceInstanceRoleGroupService { - + @Autowired private ClusterServiceInstanceService serviceInstanceService; - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Autowired private ClusterServiceRoleGroupConfigService roleGroupConfigService; - + private static final String DEFAULT = "default"; - + @Override public ClusterServiceInstanceRoleGroup getRoleGroupByServiceInstanceId( Integer serviceInstanceId) { @@ -69,7 +71,7 @@ public ClusterServiceInstanceRoleGroup getRoleGroupByServiceInstanceId( .eq(Constants.SERVICE_INSTANCE_ID, serviceInstanceId) .eq(Constants.ROLE_GROUP_TYPE, DEFAULT)); } - + @Override public Result saveRoleGroup( Integer serviceInstanceId, Integer roleGroupId, String roleGroupName) { @@ -97,7 +99,7 @@ public Result saveRoleGroup( roleGroupConfigService.save(roleGroupConfig); return Result.success(); } - + private boolean isRepeatRoleGroupName(Integer serviceInstanceId, String roleGroupName) { List list = this.list( @@ -109,7 +111,7 @@ private boolean isRepeatRoleGroupName(Integer serviceInstanceId, String roleGrou } return false; } - + @Override public Result bind(String roleInstanceIds, Integer roleGroupId) { String[] ids = roleInstanceIds.split(","); @@ -129,9 +131,9 @@ public Result bind(String roleInstanceIds, Integer roleGroupId) { roleInstanceService.updateBatchById(list); return Result.success(); } - + private boolean isSameRoleGroup(ClusterServiceRoleInstanceEntity roleInstanceEntity, List ids) { - + // query role instance by hostname and servicename List roleList = roleInstanceService.listRoleIns(roleInstanceEntity.getHostname(), roleInstanceEntity.getServiceName()); @@ -141,7 +143,7 @@ private boolean isSameRoleGroup(ClusterServiceRoleInstanceEntity roleInstanceEnt } return false; } - + private boolean isSameConfig(Integer oldRoleGroupId, Integer newRoleGroupId) { ClusterServiceRoleGroupConfig oldConfig = roleGroupConfigService.getConfigByRoleGroupId(oldRoleGroupId); @@ -152,7 +154,7 @@ private boolean isSameConfig(Integer oldRoleGroupId, Integer newRoleGroupId) { } return false; } - + @Override public ClusterServiceRoleGroupConfig getRoleGroupConfigByServiceId(Integer serviceInstanceId) { ClusterServiceInstanceRoleGroup instanceRoleGroup = @@ -162,7 +164,7 @@ public ClusterServiceRoleGroupConfig getRoleGroupConfigByServiceId(Integer servi .eq(Constants.ROLE_GROUP_TYPE, DEFAULT)); return roleGroupConfigService.getConfigByRoleGroupId(instanceRoleGroup.getId()); } - + @Override public Result rename(Integer roleGroupId, String roleGroupName) { ClusterServiceInstanceRoleGroup roleGroup = this.getById(roleGroupId); @@ -174,7 +176,7 @@ && isRepeatRoleGroupName(roleGroup.getServiceInstanceId(), roleGroupName)) { this.updateById(roleGroup); return Result.success(); } - + @Override public Result deleteRoleGroup(Integer roleGroupId) { if (hasRoleInstanceUse(roleGroupId)) { @@ -187,7 +189,7 @@ public Result deleteRoleGroup(Integer roleGroupId) { roleGroupConfigService.removeAllByRoleGroupId(roleGroupId); return Result.success(); } - + private boolean isDefaultRoleGroup(Integer roleGroupId) { ClusterServiceInstanceRoleGroup roleGroup = this.getById(roleGroupId); String roleGroupType = roleGroup.getRoleGroupType(); @@ -196,23 +198,23 @@ private boolean isDefaultRoleGroup(Integer roleGroupId) { } return false; } - + @Override public List listRoleGroupByServiceInstanceId( Integer serviceInstanceId) { - + return this.list( new QueryWrapper() .eq(Constants.SERVICE_INSTANCE_ID, serviceInstanceId)); } - + @Override public void updateToNeedRestart(Integer roleGroupId) { ClusterServiceInstanceRoleGroup roleGroup = this.getById(roleGroupId); roleGroup.setNeedRestart(NeedRestart.YES); this.updateById(roleGroup); } - + private boolean hasRoleInstanceUse(Integer roleGroupId) { List list = roleInstanceService.list( diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceServiceImpl.java index 286ead36..0c920add 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceInstanceServiceImpl.java @@ -17,25 +17,35 @@ package com.datasophon.api.service.impl; -import com.alibaba.fastjson.JSONArray; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.load.GlobalVariables; -import com.datasophon.api.service.*; +import com.datasophon.api.service.ClusterAlertHistoryService; +import com.datasophon.api.service.ClusterInfoService; +import com.datasophon.api.service.ClusterServiceDashboardService; +import com.datasophon.api.service.ClusterServiceInstanceRoleGroupService; +import com.datasophon.api.service.ClusterServiceInstanceService; +import com.datasophon.api.service.ClusterServiceRoleGroupConfigService; +import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.ClusterServiceRoleInstanceWebuisService; +import com.datasophon.api.service.ClusterVariableService; +import com.datasophon.api.service.FrameServiceRoleService; import com.datasophon.common.Constants; import com.datasophon.common.model.SimpleServiceConfig; import com.datasophon.common.utils.CollectionUtils; import com.datasophon.common.utils.PlaceholderUtils; import com.datasophon.common.utils.Result; -import com.datasophon.dao.entity.*; +import com.datasophon.dao.entity.ClusterAlertHistory; +import com.datasophon.dao.entity.ClusterServiceDashboard; +import com.datasophon.dao.entity.ClusterServiceInstanceEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceRoleGroup; +import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; +import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; +import com.datasophon.dao.entity.ClusterVariable; +import com.datasophon.dao.entity.FrameServiceRoleEntity; import com.datasophon.dao.enums.NeedRestart; import com.datasophon.dao.enums.ServiceRoleState; import com.datasophon.dao.enums.ServiceState; import com.datasophon.dao.mapper.ClusterServiceInstanceMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; @@ -43,44 +53,52 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.alibaba.fastjson.JSONArray; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterServiceInstanceService") @Transactional public class ClusterServiceInstanceServiceImpl extends - ServiceImpl + ServiceImpl implements - ClusterServiceInstanceService { - + ClusterServiceInstanceService { + @Autowired private ClusterServiceInstanceMapper serviceInstanceMapper; - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Autowired private ClusterServiceDashboardService dashboardService; - + @Autowired private ClusterInfoService clusterInfoService; - + @Autowired private ClusterAlertHistoryService alertHistoryService; - + @Autowired private FrameServiceRoleService frameServiceRoleService; - + @Autowired private ClusterServiceRoleGroupConfigService roleGroupConfigService; - + @Autowired private ClusterServiceInstanceRoleGroupService roleGroupService; - + @Autowired private ClusterServiceRoleInstanceWebuisService webuisService; - + @Autowired private ClusterVariableService variableService; - + @Override public ClusterServiceInstanceEntity getServiceInstanceByClusterIdAndServiceName(Integer clusterId, String serviceName) { @@ -88,12 +106,12 @@ public ClusterServiceInstanceEntity getServiceInstanceByClusterIdAndServiceName( .eq(Constants.CLUSTER_ID, clusterId) .eq(Constants.SERVICE_NAME, serviceName)); } - + @Override public String getServiceConfigByClusterIdAndServiceName(Integer clusterId, String serviceName) { return serviceInstanceMapper.getServiceConfigByClusterIdAndServiceName(clusterId, serviceName); } - + @Override public List listAll(Integer clusterId) { Map globalVariables = GlobalVariables.get(clusterId); @@ -121,7 +139,7 @@ public List listAll(Integer clusterId) { serviceInstance.setServiceState(ServiceState.WAIT_INSTALL); needUpdate = true; } - + // 查询停止状态角色 List roleList = roleInstanceService.lambdaQuery() .eq(ClusterServiceRoleInstanceEntity::getServiceId, serviceInstance.getId()) @@ -157,7 +175,7 @@ public List listAll(Integer clusterId) { needUpdate = true; } } - + // 查询是否进行了配置更新 List obsoleteRoleList = roleInstanceService.getObsoleteService(serviceInstance.getId()); @@ -172,13 +190,13 @@ public List listAll(Integer clusterId) { } return list; } - + @Override public Result downloadClientConfig(Integer clusterId, String serviceName) { - + return null; } - + @Override public Result getServiceRoleType(Integer serviceInstanceId) { ClusterServiceInstanceEntity serviceInstanceEntity = this.getById(serviceInstanceId); @@ -186,7 +204,7 @@ public Result getServiceRoleType(Integer serviceInstanceId) { List list = frameServiceRoleService.getAllServiceRoleList(frameServiceId); return Result.success(list); } - + @Override public Result configVersionCompare(Integer serviceInstanceId, Integer roleGroupId) { List list = @@ -200,13 +218,13 @@ public Result configVersionCompare(Integer serviceInstanceId, Integer roleGroupI String newConfigJson = newConfig.getConfigJson(); List newSimpleServiceConfigs = JSONArray.parseArray(newConfigJson, SimpleServiceConfig.class); - + String oldConfigJson = oldConfig.getConfigJson(); List oldSimpleServiceConfigs = JSONArray.parseArray(oldConfigJson, SimpleServiceConfig.class); map.put("newConfig", newSimpleServiceConfigs); map.put("oldConfig", oldSimpleServiceConfigs); - + } else if (list.size() == 1) { ClusterServiceRoleGroupConfig newConfig = list.get(0); String newConfigJson = newConfig.getConfigJson(); @@ -217,7 +235,7 @@ public Result configVersionCompare(Integer serviceInstanceId, Integer roleGroupI } return Result.success(map); } - + @Override public Result delServiceInstance(Integer serviceInstanceId) { if (hasRunningRoleInstance(serviceInstanceId)) { @@ -225,17 +243,19 @@ public Result delServiceInstance(Integer serviceInstanceId) { } List roleGroups = roleGroupService.listRoleGroupByServiceInstanceId(serviceInstanceId); - List roleGroupIds = roleGroups.stream().map(ClusterServiceInstanceRoleGroup::getId).collect(Collectors.toList()); + List roleGroupIds = + roleGroups.stream().map(ClusterServiceInstanceRoleGroup::getId).collect(Collectors.toList()); List roleGroupConfigList = roleGroupConfigService.listRoleGroupConfigsByRoleGroupIds(roleGroupIds); List roleInstanceList = roleInstanceService.getServiceRoleInstanceListByServiceId(serviceInstanceId); - + // del role group roleGroupService.removeByIds(roleGroupIds); // del role group config roleGroupConfigService - .removeByIds(roleGroupConfigList.stream().map(ClusterServiceRoleGroupConfig::getId).collect(Collectors.toList())); + .removeByIds(roleGroupConfigList.stream().map(ClusterServiceRoleGroupConfig::getId) + .collect(Collectors.toList())); // del service role instance if (!roleInstanceList.isEmpty()) { List roleInsIds = @@ -244,28 +264,30 @@ public Result delServiceInstance(Integer serviceInstanceId) { } // del web uis webuisService.removeByServiceInsId(serviceInstanceId); - + // del service instance this.removeById(serviceInstanceId); // del variable roleGroups.forEach(roleGroup -> { - List variables = variableService.getVariables(roleGroup.getClusterId(), roleGroup.getServiceName()); + List variables = + variableService.getVariables(roleGroup.getClusterId(), roleGroup.getServiceName()); if (CollectionUtils.isNotEmpty(variables)) { Map variablesMap = GlobalVariables.get(roleGroup.getClusterId()); variables.forEach(var -> variablesMap.remove(var.getVariableName())); - variableService.removeByIds(variables.stream().map(ClusterVariable::getId).collect(Collectors.toList())); + variableService + .removeByIds(variables.stream().map(ClusterVariable::getId).collect(Collectors.toList())); } }); return Result.success(); } - + @Override public List listRunningServiceInstance(Integer clusterId) { return this.list(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId) .eq(Constants.SERVICE_STATE, ServiceState.RUNNING)); } - + public boolean hasRunningRoleInstance(Integer serviceInstanceId) { List list = roleInstanceService.getRunningServiceRoleInstanceListByServiceId(serviceInstanceId); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleGroupConfigServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleGroupConfigServiceImpl.java index b1e6cf9c..9d657d50 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleGroupConfigServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleGroupConfigServiceImpl.java @@ -17,41 +17,43 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterServiceRoleGroupConfigService; import com.datasophon.common.Constants; import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; import com.datasophon.dao.mapper.ClusterServiceRoleGroupConfigMapper; -import org.springframework.stereotype.Service; import java.util.List; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterServiceRoleGroupConfigService") public class ClusterServiceRoleGroupConfigServiceImpl extends ServiceImpl implements ClusterServiceRoleGroupConfigService { - + @Override public ClusterServiceRoleGroupConfig getConfigByRoleGroupId(Integer roleGroupId) { return this.getOne(new QueryWrapper() .eq(Constants.ROLE_GROUP_ID, roleGroupId).orderByDesc(Constants.CONFIG_VERSION).last("limit 1")); } - + @Override public ClusterServiceRoleGroupConfig getConfigByRoleGroupIdAndVersion(Integer roleGroupId, Integer version) { return this.getOne(new QueryWrapper() .eq(Constants.ROLE_GROUP_ID, roleGroupId).eq(Constants.CONFIG_VERSION, version)); } - + @Override public void removeAllByRoleGroupId(Integer roleGroupId) { this.remove(new QueryWrapper() .eq(Constants.ROLE_GROUP_ID, roleGroupId)); } - + @Override public List listRoleGroupConfigsByRoleGroupIds(List roleGroupIds) { List list = this.list(new QueryWrapper() diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceConfigServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceConfigServiceImpl.java index 7a0938ea..98a1b318 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceConfigServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceConfigServiceImpl.java @@ -17,17 +17,19 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterServiceRoleInstanceConfigService; import com.datasophon.dao.entity.ClusterServiceRoleInstanceConfigEntity; import com.datasophon.dao.mapper.ClusterServiceRoleInstanceConfigMapper; + import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterServiceRoleInstanceConfigService") public class ClusterServiceRoleInstanceConfigServiceImpl extends ServiceImpl implements ClusterServiceRoleInstanceConfigService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceServiceImpl.java index 13d1345a..1151a6ac 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceServiceImpl.java @@ -17,12 +17,6 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.master.ActorUtils; @@ -51,11 +45,9 @@ import com.datasophon.dao.enums.RoleType; import com.datasophon.dao.enums.ServiceRoleState; import com.datasophon.dao.mapper.ClusterServiceRoleInstanceMapper; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -69,42 +61,55 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; + @Service("clusterServiceRoleInstanceService") public class ClusterServiceRoleInstanceServiceImpl extends ServiceImpl implements ClusterServiceRoleInstanceService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterServiceRoleInstanceServiceImpl.class); - + @Autowired ClusterInfoService clusterInfoService; - + @Autowired FrameServiceRoleService frameServiceRoleService; - + @Autowired FrameServiceService frameService; - + @Autowired ClusterServiceRoleInstanceService roleInstanceService; - + @Autowired private ClusterServiceCommandService commandService; - + @Autowired private ClusterServiceInstanceRoleGroupService roleGroupService; - + @Autowired private ClusterServiceRoleInstanceMapper roleInstanceMapper; - + @Autowired private ClusterAlertHistoryService alertHistoryService; - + @Autowired private ClusterServiceRoleInstanceWebuisService webuisService; - + @Override public List listStoppedServiceRoleListByHostnameAndClusterId(String hostname, Integer clusterId) { @@ -114,7 +119,7 @@ public List listStoppedServiceRoleListByHostna .eq(ClusterServiceRoleInstanceEntity::getServiceRoleState, ServiceRoleState.STOP) .list(); } - + @Override public List getServiceRoleListByHostnameAndClusterId(String hostname, Integer clusterId) { @@ -122,7 +127,7 @@ public List getServiceRoleListByHostnameAndClu .eq(Constants.CLUSTER_ID, clusterId) .eq(Constants.HOSTNAME, hostname)); } - + @Override public List getServiceRoleInstanceListByServiceIdAndRoleState(Integer serviceId, ServiceRoleState stop) { @@ -131,7 +136,7 @@ public List getServiceRoleInstanceListByServic .eq(ClusterServiceRoleInstanceEntity::getServiceRoleState, stop) .list(); } - + @Override public ClusterServiceRoleInstanceEntity getOneServiceRole(String name, String hostname, Integer id) { List list = this.list(new QueryWrapper() @@ -143,12 +148,12 @@ public ClusterServiceRoleInstanceEntity getOneServiceRole(String name, String ho } return null; } - + @Override public Result listAll(Integer serviceInstanceId, String hostname, Integer serviceRoleState, String serviceRoleName, Integer roleGroupId, Integer page, Integer pageSize) { int offset = (page - 1) * pageSize; - + LambdaQueryChainWrapper wrapper = this.lambdaQuery() .eq(ClusterServiceRoleInstanceEntity::getServiceId, serviceInstanceId) .eq(Objects.nonNull(serviceRoleState), ClusterServiceRoleInstanceEntity::getServiceRoleState, @@ -164,7 +169,7 @@ public Result listAll(Integer serviceInstanceId, String hostname, Integer servic if (CollectionUtils.isEmpty(cluServiceRoleInstList)) { return Result.successEmptyCount(); } - + for (ClusterServiceRoleInstanceEntity roleInstanceEntity : cluServiceRoleInstList) { ClusterServiceInstanceRoleGroup roleGroup = roleGroupService.getById(roleInstanceEntity.getRoleGroupId()); if (Objects.nonNull(roleGroup)) { @@ -172,10 +177,10 @@ public Result listAll(Integer serviceInstanceId, String hostname, Integer servic } roleInstanceEntity.setServiceRoleStateCode(roleInstanceEntity.getServiceRoleState().getValue()); } - + return Result.success(cluServiceRoleInstList).put(Constants.TOTAL, count); } - + @Override public Result getLog(Integer serviceRoleInstanceId) throws Exception { ClusterServiceRoleInstanceEntity roleInstance = this.getById(serviceRoleInstanceId); @@ -196,7 +201,7 @@ public Result getLog(Integer serviceRoleInstanceId) throws Exception { command.setLogFile(logFile); command.setDecompressPackageName(frameServiceEntity.getDecompressPackageName()); logger.info("start to get {} log from {}", serviceRole.getServiceRoleName(), roleInstance.getHostname()); - + ActorSelection configActor = ActorUtils.actorSystem .actorSelection("akka.tcp://datasophon@" + roleInstance.getHostname() + ":2552/user/worker/logActor"); Timeout timeout = new Timeout(Duration.create(60, TimeUnit.SECONDS)); @@ -207,17 +212,17 @@ public Result getLog(Integer serviceRoleInstanceId) throws Exception { } return Result.success(); } - + @Override public List getServiceRoleInstanceListByServiceId(int id) { return this.lambdaQuery().eq(ClusterServiceRoleInstanceEntity::getServiceId, id).list(); } - + @Override public List getServiceRoleInstanceListByClusterId(int clusterId) { return this.lambdaQuery().eq(ClusterServiceRoleInstanceEntity::getClusterId, clusterId).list(); } - + @Override public Result deleteServiceRole(List idList) { Collection list = this.listByIds(idList); @@ -236,18 +241,18 @@ public Result deleteServiceRole(List idList) { this.removeByIds(needRemoveList); // delete if there is a webui webuisService.removeByRoleInsIds(needRemoveList); - + } return flag ? Result.error(Status.EXIT_RUNNING_INSTANCES.getMsg()) : Result.success(); } - + @Override public List getServiceRoleInstanceListByClusterIdAndRoleName(Integer clusterId, String roleName) { - return this.list(new QueryWrapper() + return this.list(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId).eq(Constants.SERVICE_ROLE_NAME, roleName)); } - + @Override public List getRunningServiceRoleInstanceListByServiceId(Integer serviceInstanceId) { return this.lambdaQuery() @@ -255,7 +260,7 @@ public List getRunningServiceRoleInstanceListB .eq(ClusterServiceRoleInstanceEntity::getServiceRoleState, ServiceRoleState.RUNNING) .list(); } - + @Override public Result restartObsoleteService(Integer roleGroupId) { ClusterServiceInstanceRoleGroup roleGroup = roleGroupService.getById(roleGroupId); @@ -271,7 +276,7 @@ public Result restartObsoleteService(Integer roleGroupId) { } return Result.success(); } - + @Override public Result decommissionNode(String serviceRoleInstanceIds, String serviceName) throws Exception { TreeSet hosts = new TreeSet<>(); @@ -309,17 +314,17 @@ public Result decommissionNode(String serviceRoleInstanceIds, String serviceName } return Result.success(); } - + @Override public void updateToNeedRestart(Integer roleGroupId) { roleInstanceMapper.updateToNeedRestart(roleGroupId); } - + @Override public void updateToNeedRestartByHost(String hostName) { roleInstanceMapper.updateToNeedRestartByHost(hostName); } - + @Override public List getObsoleteService(Integer serviceInstanceId) { return this.lambdaQuery() @@ -327,7 +332,7 @@ public List getObsoleteService(Integer service .eq(ClusterServiceRoleInstanceEntity::getNeedRestart, NeedRestart.YES) .list(); } - + @Override public List getStoppedRoleInstanceOnHost(Integer clusterId, String hostname, ServiceRoleState state) { @@ -336,7 +341,7 @@ public List getStoppedRoleInstanceOnHost(Integ .eq(Constants.HOSTNAME, hostname) .eq(Constants.SERVICE_ROLE_STATE, state)); } - + @Override public void reomveRoleInstance(Integer serviceInstanceId) { this.lambdaUpdate() @@ -344,27 +349,27 @@ public void reomveRoleInstance(Integer serviceInstanceId) { .eq(ClusterServiceRoleInstanceEntity::getServiceRoleState, ServiceRoleState.STOP) .remove(); } - + @Override public ClusterServiceRoleInstanceEntity getKAdminRoleIns(Integer clusterId) { return this.getOne(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId) .eq(Constants.SERVICE_ROLE_NAME, "KAdmin")); } - + @Override public List listServiceRoleByName(String name) { return this.list(new QueryWrapper() .eq(Constants.SERVICE_ROLE_NAME, name)); } - + @Override public ClusterServiceRoleInstanceEntity getServiceRoleInsByHostAndName(String hostName, String serviceRoleName) { return this.getOne(new QueryWrapper() .eq(Constants.HOSTNAME, hostName) .eq(Constants.SERVICE_ROLE_NAME, serviceRoleName)); } - + @Override public List listRoleIns(String hostname, String serviceName) { return this.lambdaQuery() diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceWebuisServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceWebuisServiceImpl.java index 5611faf3..c6779bae 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceWebuisServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterServiceRoleInstanceWebuisServiceImpl.java @@ -19,29 +19,31 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterServiceRoleInstanceWebuisService; import com.datasophon.common.Constants; import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.ClusterServiceRoleInstanceWebuis; import com.datasophon.dao.mapper.ClusterServiceRoleInstanceWebuisMapper; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterServiceRoleInstanceWebuisService") public class ClusterServiceRoleInstanceWebuisServiceImpl extends ServiceImpl implements ClusterServiceRoleInstanceWebuisService { - + private static final String ACTIVE = "(Active)"; - + private static final String STANDBY = "(Standby)"; - + @Override public Result getWebUis(Integer serviceInstanceId) { List list = @@ -50,45 +52,45 @@ public Result getWebUis(Integer serviceInstanceId) { .eq(Constants.SERVICE_INSTANCE_ID, serviceInstanceId)); return Result.success(list); } - + @Override public void removeByServiceInsId(Integer serviceInstanceId) { this.remove( new QueryWrapper() .eq(Constants.SERVICE_INSTANCE_ID, serviceInstanceId)); } - + @Override public void updateWebUiToActive(Integer roleInstanceId) { updateWebUiName(roleInstanceId, ACTIVE); } - + @Override public ClusterServiceRoleInstanceWebuis getRoleInstanceWebUi(Integer roleInstanceId) { return this.lambdaQuery() .eq(ClusterServiceRoleInstanceWebuis::getServiceRoleInstanceId, roleInstanceId) .one(); } - + @Override public void removeByRoleInsIds(ArrayList needRemoveList) { this.lambdaUpdate() .in(ClusterServiceRoleInstanceWebuis::getServiceRoleInstanceId, needRemoveList) .remove(); } - + @Override public void updateWebUiToStandby(Integer roleInstanceId) { updateWebUiName(roleInstanceId, STANDBY); } - + @Override public List listWebUisByServiceInstanceId(Integer serviceInstanceId) { return this.list( - new QueryWrapper() - .eq(Constants.SERVICE_INSTANCE_ID, serviceInstanceId)); + new QueryWrapper() + .eq(Constants.SERVICE_INSTANCE_ID, serviceInstanceId)); } - + private void updateWebUiName(Integer roleInstanceId, String state) { ClusterServiceRoleInstanceWebuis webuis = this.lambdaQuery() diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserGroupServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserGroupServiceImpl.java index d44ae6d4..e232d9a3 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserGroupServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserGroupServiceImpl.java @@ -17,8 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterGroupService; import com.datasophon.api.service.ClusterUserGroupService; import com.datasophon.api.service.ClusterUserService; @@ -27,36 +25,40 @@ import com.datasophon.dao.entity.ClusterUser; import com.datasophon.dao.entity.ClusterUserGroup; import com.datasophon.dao.mapper.ClusterUserGroupMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterUserGroupService") public class ClusterUserGroupServiceImpl extends ServiceImpl implements ClusterUserGroupService { - + @Autowired private ClusterGroupService clusterGroupService; - + @Autowired private ClusterUserService userService; - + @Override public Integer countGroupUserNum(Integer groupId) { int count = this.count(new QueryWrapper().eq(Constants.GROUP_ID, groupId)); return count; } - + @Override public void deleteByUser(Integer id) { this.remove(new QueryWrapper().eq(Constants.USER_ID, id)); } - + @Override public ClusterGroup queryMainGroup(Integer userId) { List clusterUserGroups = @@ -64,7 +66,7 @@ public ClusterGroup queryMainGroup(Integer userId) { List groupIds = clusterUserGroups.stream().map(e -> e.getGroupId()).collect(Collectors.toList()); return clusterGroupService.getById(groupIds.get(0)); } - + @Override public List listOtherGroups(Integer userId) { List clusterUserGroups = @@ -76,7 +78,7 @@ public List listOtherGroups(Integer userId) { } return null; } - + @Override public List listClusterUsers(Integer groupId) { List clusterUserGroups = diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserServiceImpl.java index dc30a141..33c5204a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterUserServiceImpl.java @@ -17,18 +17,13 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.exceptions.ServiceException; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.service.ClusterGroupService; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterUserGroupService; import com.datasophon.api.service.ClusterUserService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.common.Constants; import com.datasophon.common.command.remote.CreateUnixUserCommand; import com.datasophon.common.command.remote.DelUnixUserCommand; @@ -39,12 +34,9 @@ import com.datasophon.dao.entity.ClusterUser; import com.datasophon.dao.entity.ClusterUserGroup; import com.datasophon.dao.mapper.ClusterUserMapper; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -56,34 +48,47 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; + @Service("clusterUserService") @Transactional public class ClusterUserServiceImpl extends ServiceImpl implements ClusterUserService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterUserServiceImpl.class); @Autowired private ClusterGroupService groupService; - + @Autowired private ClusterHostService hostService; - + @Autowired private ClusterUserGroupService userGroupService; - + @Override public Result create(Integer clusterId, String username, Integer mainGroupId, String groupIds) { - + if (hasRepeatUserName(clusterId, username)) { return Result.error(Status.DUPLICATE_USER_NAME.getMsg()); } List hostList = hostService.getHostListByClusterId(clusterId); - + ClusterUser clusterUser = new ClusterUser(); clusterUser.setUsername(username); clusterUser.setClusterId(clusterId); this.save(clusterUser); buildClusterUserGroup(clusterId, clusterUser.getId(), mainGroupId, 1); - + String otherGroup = null; if (StringUtils.isNotBlank(groupIds)) { List otherGroupIds = @@ -94,18 +99,18 @@ public Result create(Integer clusterId, String username, Integer mainGroupId, St Collection clusterGroups = groupService.listByIds(otherGroupIds); otherGroup = clusterGroups.stream().map(e -> e.getGroupName()).collect(Collectors.joining(",")); } - + ClusterGroup mainGroup = groupService.getById(mainGroupId); // sync to all hosts for (ClusterHostDO clusterHost : hostList) { ActorSelection unixUserActor = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + clusterHost.getHostname() + ":2552/user/worker/unixUserActor"); - + CreateUnixUserCommand createUnixUserCommand = new CreateUnixUserCommand(); createUnixUserCommand.setUsername(username); createUnixUserCommand.setMainGroup(mainGroup.getGroupName()); createUnixUserCommand.setOtherGroups(otherGroup); - + Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); Future execFuture = Patterns.ask(unixUserActor, createUnixUserCommand, timeout); ExecResult execResult = null; @@ -125,7 +130,7 @@ public Result create(Integer clusterId, String username, Integer mainGroupId, St } return Result.success(); } - + private void buildClusterUserGroup(Integer clusterId, Integer userId, Integer groupId, Integer userGroupType) { ClusterUserGroup clusterUserGroup = new ClusterUserGroup(); clusterUserGroup.setUserId(userId); @@ -134,7 +139,7 @@ private void buildClusterUserGroup(Integer clusterId, Integer userId, Integer gr clusterUserGroup.setUserGroupType(userGroupType); userGroupService.save(clusterUserGroup); } - + private boolean hasRepeatUserName(Integer clusterId, String username) { List list = this.list(new QueryWrapper() .eq(Constants.CLUSTER_ID, clusterId) @@ -144,7 +149,7 @@ private boolean hasRepeatUserName(Integer clusterId, String username) { } return false; } - + @Override public Result listPage(Integer clusterId, String username, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; @@ -167,7 +172,7 @@ public Result listPage(Integer clusterId, String username, Integer page, Integer .eq(Constants.CLUSTER_ID, clusterId)); return Result.success(list).put(Constants.TOTAL, total); } - + @Override public Result deleteClusterUser(Integer id) { ClusterUser clusterUser = this.getById(id); @@ -197,12 +202,12 @@ public Result deleteClusterUser(Integer id) { this.removeById(id); return Result.success(); } - + @Override public List listAllUser(Integer clusterId) { return this.lambdaQuery().eq(ClusterUser::getClusterId, clusterId).list(); } - + @Override public void createUnixUserOnHost(ClusterUser clusterUser, String hostname) { String username = clusterUser.getUsername(); @@ -214,12 +219,12 @@ public void createUnixUserOnHost(ClusterUser clusterUser, String hostname) { } ActorSelection unixUserActor = ActorUtils.actorSystem .actorSelection("akka.tcp://datasophon@" + hostname + ":2552/user/worker/unixUserActor"); - + CreateUnixUserCommand createUnixUserCommand = new CreateUnixUserCommand(); createUnixUserCommand.setUsername(clusterUser.getUsername()); createUnixUserCommand.setMainGroup(mainGroup.getGroupName()); createUnixUserCommand.setOtherGroups(otherGroup); - + Timeout timeout = new Timeout(Duration.create(180, TimeUnit.SECONDS)); Future execFuture = Patterns.ask(unixUserActor, createUnixUserCommand, timeout); ExecResult execResult = null; @@ -234,6 +239,6 @@ public void createUnixUserOnHost(ClusterUser clusterUser, String hostname) { } catch (Exception e) { throw new ServiceException(500, "create unix user " + username + " failed at " + hostname); } - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterVariableServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterVariableServiceImpl.java index 9077c46d..489e83e4 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterVariableServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterVariableServiceImpl.java @@ -17,23 +17,25 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterVariableService; import com.datasophon.common.Constants; import com.datasophon.dao.entity.ClusterVariable; import com.datasophon.dao.mapper.ClusterVariableMapper; -import org.springframework.stereotype.Service; import java.util.List; import java.util.Objects; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterVariableService") public class ClusterVariableServiceImpl extends ServiceImpl implements - ClusterVariableService { - + ClusterVariableService { + @Override public ClusterVariable getVariableByVariableName(String variableName, Integer clusterId) { List list = this.list(new QueryWrapper() @@ -43,12 +45,11 @@ public ClusterVariable getVariableByVariableName(String variableName, Integer cl } return null; } - + @Override public List getVariables(Integer clusterId, String serviceName) { return this.list(new LambdaQueryWrapper() .eq(ClusterVariable::getClusterId, clusterId) - .eq(ClusterVariable::getServiceName, serviceName) - ); + .eq(ClusterVariable::getServiceName, serviceName)); } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnQueueServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnQueueServiceImpl.java index c0423503..bb085847 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnQueueServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnQueueServiceImpl.java @@ -17,13 +17,6 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; -import cn.hutool.core.bean.BeanUtil; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.handler.service.ServiceConfigureHandler; @@ -39,11 +32,9 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.entity.ClusterYarnQueue; import com.datasophon.dao.mapper.ClusterYarnQueueMapper; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -53,16 +44,30 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +import cn.hutool.core.bean.BeanUtil; + @Service("clusterYarnQueueService") public class ClusterYarnQueueServiceImpl extends ServiceImpl implements ClusterYarnQueueService { - + private static final Logger logger = LoggerFactory.getLogger(ClusterYarnQueueServiceImpl.class); - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Override public Result listByPage(Integer clusterId, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; @@ -80,7 +85,7 @@ public Result listByPage(Integer clusterId, Integer page, Integer pageSize) { } return Result.success(list).put(Constants.TOTAL, count); } - + @Override public Result refreshQueues(Integer clusterId) throws Exception { List list = this.list(new QueryWrapper() @@ -88,7 +93,7 @@ public Result refreshQueues(Integer clusterId) throws Exception { // 查询resourcemanager节点 List roleList = roleInstanceService.getServiceRoleInstanceListByClusterIdAndRoleName(clusterId, "ResourceManager"); - + // 构建configfilemap HashMap> configFileMap = new HashMap<>(); Generators generators = new Generators(); @@ -96,7 +101,7 @@ public Result refreshQueues(Integer clusterId) throws Exception { generators.setOutputDirectory("etc/hadoop"); generators.setConfigFormat("custom"); generators.setTemplateName("fair-scheduler.ftl"); - + ArrayList serviceConfigs = new ArrayList<>(); ServiceConfig config = new ServiceConfig(); ArrayList queueList = new ArrayList<>(); @@ -114,7 +119,7 @@ public Result refreshQueues(Integer clusterId) throws Exception { config.setConfigType("map"); config.setRequired(true); serviceConfigs.add(config); - + configFileMap.put(generators, serviceConfigs); String hostname = ""; for (ClusterServiceRoleInstanceEntity roleInstanceEntity : roleList) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnSchedulerServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnSchedulerServiceImpl.java index 52893bd5..c1c0b66f 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnSchedulerServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterYarnSchedulerServiceImpl.java @@ -17,24 +17,26 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterYarnSchedulerService; import com.datasophon.common.Constants; import com.datasophon.dao.entity.ClusterYarnScheduler; import com.datasophon.dao.mapper.ClusterYarnSchedulerMapper; + import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("clusterYarnSchedulerService") public class ClusterYarnSchedulerServiceImpl extends ServiceImpl implements ClusterYarnSchedulerService { - + @Override public ClusterYarnScheduler getScheduler(Integer clusterId) { return this.getOne(new QueryWrapper().eq(Constants.CLUSTER_ID, clusterId)); } - + @Override public void createDefaultYarnScheduler(Integer clusterId) { ClusterYarnScheduler scheduler = new ClusterYarnScheduler(); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterZkServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterZkServiceImpl.java index 0b1ae7d6..dc68e177 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterZkServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ClusterZkServiceImpl.java @@ -17,28 +17,30 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterZkService; import com.datasophon.common.Constants; import com.datasophon.dao.entity.ClusterZk; import com.datasophon.dao.mapper.ClusterZkMapper; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service("clusterZkService") public class ClusterZkServiceImpl extends ServiceImpl implements ClusterZkService { - + @Autowired private ClusterZkMapper clusterZkMapper; - + @Override public Integer getMaxMyId(Integer clusterId) { return clusterZkMapper.getMaxMyId(clusterId); } - + @Override public List getAllZkServer(Integer clusterId) { return this.list(new QueryWrapper().eq(Constants.CLUSTER_ID, clusterId)); diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameInfoServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameInfoServiceImpl.java index 92a1a862..1b8a1ea8 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameInfoServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameInfoServiceImpl.java @@ -17,7 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.FrameInfoService; import com.datasophon.api.service.FrameServiceService; import com.datasophon.common.utils.CollectionUtils; @@ -25,36 +24,41 @@ import com.datasophon.dao.entity.FrameInfoEntity; import com.datasophon.dao.entity.FrameServiceEntity; import com.datasophon.dao.mapper.FrameInfoMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("frameInfoService") public class FrameInfoServiceImpl extends ServiceImpl implements FrameInfoService { - + @Autowired private FrameServiceService frameServiceService; - + @Override public Result getAllClusterFrame() { List frameInfoEntities = this.list(); if (CollectionUtils.isEmpty(frameInfoEntities)) { return Result.success(); } - + Set frameInfoIds = frameInfoEntities.stream().map(FrameInfoEntity::getId).collect(Collectors.toSet()); Map> frameServiceGroupBys = frameServiceService.lambdaQuery() - .select(FrameServiceEntity::getId, FrameServiceEntity::getFrameId, FrameServiceEntity::getFrameCode, FrameServiceEntity::getServiceName, FrameServiceEntity::getServiceVersion, FrameServiceEntity::getServiceDesc) + .select(FrameServiceEntity::getId, FrameServiceEntity::getFrameId, FrameServiceEntity::getFrameCode, + FrameServiceEntity::getServiceName, FrameServiceEntity::getServiceVersion, + FrameServiceEntity::getServiceDesc) .in(FrameServiceEntity::getFrameId, frameInfoIds) .list() .stream() .collect(Collectors.groupingBy(FrameServiceEntity::getFrameId)); frameInfoEntities.forEach(f -> f.setFrameServiceList(frameServiceGroupBys.get(f.getId()))); - + return Result.success(frameInfoEntities); } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceRoleServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceRoleServiceImpl.java index e5dc0af4..1dfb3073 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceRoleServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceRoleServiceImpl.java @@ -17,8 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterServiceRoleInstanceService; import com.datasophon.api.service.FrameServiceRoleService; @@ -32,8 +30,6 @@ import com.datasophon.dao.entity.FrameServiceRoleEntity; import com.datasophon.dao.enums.RoleType; import com.datasophon.dao.mapper.FrameServiceRoleMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; @@ -42,20 +38,26 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("frameServiceRoleService") public class FrameServiceRoleServiceImpl extends ServiceImpl implements FrameServiceRoleService { - + @Autowired private ClusterInfoService clusterInfoService; - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + @Autowired private FrameServiceService frameService; - + @Override public Result getServiceRoleList(Integer clusterId, String serviceIds, Integer serviceRoleType) { List ids = Arrays.asList(serviceIds.split(",")); @@ -67,7 +69,7 @@ public Result getServiceRoleList(Integer clusterId, String serviceIds, Integer s // 校验是否已安装Prometheus,Grafana,AlertManager ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); String key = clusterInfo.getClusterCode() + Constants.UNDERLINE + Constants.SERVICE_ROLE_HOST_MAPPING; - + for (FrameServiceRoleEntity role : list) { FrameServiceEntity frameServiceEntity = frameService.getById(role.getServiceId()); List roleInstanceList = @@ -87,7 +89,7 @@ public Result getServiceRoleList(Integer clusterId, String serviceIds, Integer s } return Result.success(list); } - + @Override public FrameServiceRoleEntity getServiceRoleByServiceIdAndServiceRoleName(Integer serviceId, String roleName) { return this.lambdaQuery() @@ -95,14 +97,14 @@ public FrameServiceRoleEntity getServiceRoleByServiceIdAndServiceRoleName(Intege .eq(FrameServiceRoleEntity::getServiceRoleName, roleName) .one(); } - + @Override public FrameServiceRoleEntity getServiceRoleByFrameCodeAndServiceRoleName(String clusterFrame, String serviceRoleName) { return this.getOne(new QueryWrapper() .eq(Constants.FRAME_CODE_1, clusterFrame).eq(Constants.SERVICE_ROLE_NAME, serviceRoleName)); } - + @Override public Result getNonMasterRoleList(Integer clusterId, String serviceIds) { List ids = Arrays.asList(serviceIds.split(",")); @@ -122,7 +124,7 @@ public Result getNonMasterRoleList(Integer clusterId, String serviceIds) { .eq(Constants.CLUSTER_ID, clusterId)); if (Objects.nonNull(roleInstanceList) && roleInstanceList.size() > 0) { hosts = roleInstanceList.stream().map(e -> e.getHostname()).collect(Collectors.toList()); - + } else if (CacheUtils.constainsKey(key)) { Map> map = (Map>) CacheUtils.get(key); if (map.containsKey(role.getServiceRoleName())) { @@ -133,7 +135,7 @@ public Result getNonMasterRoleList(Integer clusterId, String serviceIds) { } return Result.success(list); } - + @Override public Result getServiceRoleByServiceName(Integer clusterId, String serviceName) { if ("NODE".equals(serviceName)) { @@ -151,10 +153,10 @@ public Result getServiceRoleByServiceName(Integer clusterId, String serviceName) .list(); return Result.success(list); } - + @Override public List getAllServiceRoleList(Integer frameServiceId) { return this.lambdaQuery().eq(FrameServiceRoleEntity::getServiceId, frameServiceId).list(); } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceServiceImpl.java index 0f56c2d9..d1862272 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/FrameServiceServiceImpl.java @@ -17,8 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.ClusterServiceInstanceService; import com.datasophon.api.service.FrameServiceService; @@ -31,8 +29,6 @@ import com.datasophon.dao.enums.ServiceState; import com.datasophon.dao.mapper.FrameInfoMapper; import com.datasophon.dao.mapper.FrameServiceMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.Arrays; import java.util.Collection; @@ -40,20 +36,26 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("frameServiceService") public class FrameServiceServiceImpl extends ServiceImpl implements FrameServiceService { - + @Autowired ClusterInfoService clusterInfoService; - + @Autowired FrameInfoMapper frameInfoMapper; - + @Autowired ClusterServiceInstanceService serviceInstanceService; - + @Override public Result getAllFrameService(Integer clusterId) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); @@ -65,7 +67,7 @@ public Result getAllFrameService(Integer clusterId) { setInstalled(clusterId, list); return Result.success(list); } - + private void setInstalled(Integer clusterId, List list) { for (FrameServiceEntity serviceEntity : list) { ClusterServiceInstanceEntity serviceInstance = serviceInstanceService @@ -78,13 +80,13 @@ private void setInstalled(Integer clusterId, List list) { } } } - + @Override public Result getServiceListByServiceIds(List serviceIds) { Collection list = this.listByIds(serviceIds); return Result.success(list); } - + @Override public FrameServiceEntity getServiceByFrameIdAndServiceName(Integer frameId, String serviceName) { return this.lambdaQuery() @@ -92,23 +94,23 @@ public FrameServiceEntity getServiceByFrameIdAndServiceName(Integer frameId, Str .eq(FrameServiceEntity::getServiceName, serviceName) .one(); } - + @Override public FrameServiceEntity getServiceByFrameCodeAndServiceName(String clusterFrame, String serviceName) { return this.getOne(new QueryWrapper() .eq(Constants.FRAME_CODE_1, clusterFrame) .eq(Constants.SERVICE_NAME, serviceName)); } - + @Override public List getAllFrameServiceByFrameCode(String clusterFrame) { return this.list(new QueryWrapper().eq(Constants.FRAME_CODE_1, clusterFrame)); } - + @Override public List listServices(String serviceIds) { List ids = Arrays.stream(serviceIds.split(",")).collect(Collectors.toList()); return this.lambdaQuery().in(FrameServiceEntity::getId, ids).list(); } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/InstallServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/InstallServiceImpl.java index 8953d8af..a0d24d51 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/InstallServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/InstallServiceImpl.java @@ -19,21 +19,15 @@ package com.datasophon.api.service.impl; -import akka.actor.ActorRef; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.crypto.SecureUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.datasophon.api.enums.Status; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.DispatcherWorkerActor; import com.datasophon.api.master.HostConnectActor; import com.datasophon.api.master.WorkerStartActor; -import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.service.ClusterInfoService; import com.datasophon.api.service.InstallService; +import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.utils.MessageResolverUtils; import com.datasophon.api.utils.MinaUtils; import com.datasophon.api.utils.ProcessUtils; @@ -54,12 +48,9 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.InstallStepEntity; import com.datasophon.dao.mapper.InstallStepMapper; -import org.apache.commons.lang.StringUtils; + +import org.apache.commons.lang3.StringUtils; import org.apache.sshd.client.session.ClientSession; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; @@ -71,22 +62,36 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +import akka.actor.ActorRef; + +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.crypto.SecureUtil; + @Service("installService") public class InstallServiceImpl implements InstallService { - + private static final Logger logger = LoggerFactory.getLogger(InstallServiceImpl.class); - + @Autowired InstallStepMapper stepMapper; - + @Autowired ClusterInfoService clusterInfoService; - + @Autowired ClusterHostService hostService; - + private static final String SSHUSER = "SSHUSER"; - + @Override public Result getInstallStep(Integer type) { List list = @@ -94,7 +99,7 @@ public Result getInstallStep(Integer type) { new QueryWrapper().eq(Constants.INSTALL_TYPE, type)); return Result.success(list); } - + /** * 1、查询缓存是否存在当前主机列表 2、存在则根据分页返回数据 3、不存在则解析hosts,产生主机列表并放入缓存中 * @@ -106,15 +111,15 @@ public Result getInstallStep(Integer type) { */ @Override public Result analysisHostList( - Integer clusterId, - String hosts, - String sshUser, - Integer sshPort, - Integer page, - Integer pageSize) { + Integer clusterId, + String hosts, + String sshUser, + Integer sshPort, + Integer page, + Integer pageSize) { Map globalVariables = GlobalVariables.get(clusterId); ProcessUtils.generateClusterVariable(globalVariables, clusterId, null, SSHUSER, sshUser); - + List list = new ArrayList<>(); hosts = hosts.replace(" ", ""); String md5 = SecureUtil.md5(hosts); @@ -126,7 +131,7 @@ public Result analysisHostList( && md5.equals(CacheUtils.getString(clusterCode + Constants.HOST_MD5))) { logger.info("get host list from cache"); map = (HashMap) CacheUtils.get(clusterCode + Constants.HOST_MAP); - + } else { logger.info("analysis host list"); String[] hostsArr = hosts.split(","); @@ -191,20 +196,20 @@ public Result analysisHostList( List result = getListPage(list, offset, pageSize); return Result.success(result).put(Constants.TOTAL, list.size()); } - + private void tellHostCheck(String clusterCode, HostInfo hostInfo) { ActorRef actor = ActorUtils.getLocalActor(HostConnectActor.class, "hostActor-" + hostInfo.getHostname()); actor.tell(new HostCheckCommand(hostInfo, clusterCode), ActorRef.noSender()); } - + public HostInfo createHostInfo( - String host, Integer sshPort, String sshUser, String clusterCode) { + String host, Integer sshPort, String sshUser, String clusterCode) { HostInfo hostInfo = new HostInfo(); - + hostInfo.setHostname(HostUtils.getHostName(host)); hostInfo.setIp(HostUtils.getIp(host)); - + // 判断是否受管 ClusterHostDO hostEntity = hostService.getClusterHostByHostname(hostInfo.getHostname()); if (ObjectUtil.isNotNull(hostEntity)) { @@ -231,7 +236,7 @@ public HostInfo createHostInfo( hostInfo.setCreateTime(new Date()); return hostInfo; } - + @Override public Result getHostCheckStatus(Integer clusterId, String sshUser, Integer sshPort) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); @@ -245,10 +250,10 @@ public Result getHostCheckStatus(Integer clusterId, String sshUser, Integer sshP .collect(Collectors.toList()); return Result.success(list); } - + @Override public Result rehostCheck( - Integer clusterId, String hostnames, String sshUser, Integer sshPort) { + Integer clusterId, String hostnames, String sshUser, Integer sshPort) { // 开启主机校验 ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); String clusterCode = clusterInfo.getClusterCode(); @@ -268,11 +273,11 @@ public Result rehostCheck( } return Result.success(); } - + @Override public Result dispatcherHostAgentList( - Integer clusterId, Integer installStateCode, Integer page, Integer pageSize) { - + Integer clusterId, Integer installStateCode, Integer page, Integer pageSize) { + ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); String clusterCode = clusterInfo.getClusterCode(); String distributeAgentKey = @@ -285,7 +290,7 @@ public Result dispatcherHostAgentList( .map(e -> e.getValue()) .filter(e -> e.getCheckResult().getCode() == 10001) .collect(Collectors.toList()); - + for (HostInfo hostInfo : list) { if (hostInfo.isManaged()) { hostInfo.setInstallStateCode(InstallState.SUCCESS.getValue()); @@ -308,7 +313,7 @@ public Result dispatcherHostAgentList( // 保存主机agent分发历史 CacheUtils.put( distributeAgentKey + Constants.UNDERLINE + hostInfo.getHostname(), true); - + } else { long timeout = DateUtil.between(hostInfo.getCreateTime(), new Date(), DateUnit.MINUTE); @@ -334,15 +339,15 @@ public Result dispatcherHostAgentList( List result = getListPage(list, offset, pageSize); return Result.success(result).put(Constants.TOTAL, list.size()); } - + @Override public Result reStartDispatcherHostAgent(Integer clusterId, String hostnames) { - + ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); String clusterCode = clusterInfo.getClusterCode(); Map map = (Map) CacheUtils.get(clusterCode + Constants.HOST_MAP); - + for (String hostname : hostnames.split(",")) { ClusterHostDO clusterHost = hostService.getClusterHostByHostname(hostname); HostInfo hostInfo = new HostInfo(); @@ -356,12 +361,12 @@ public Result reStartDispatcherHostAgent(Integer clusterId, String hostnames) { ActorRef hostActor = ActorUtils.getLocalActor( DispatcherWorkerActor.class, "dispatcherWorkerActor-" + hostname); - + hostInfo.setInstallState(InstallState.RUNNING); hostInfo.setInstallStateCode(InstallState.RUNNING.getValue()); hostInfo.setErrMsg(""); hostInfo.setProgress(0); - + hostActor.tell( new DispatcherHostAgentCommand( hostInfo, clusterId, clusterInfo.getClusterFrame()), @@ -369,7 +374,7 @@ public Result reStartDispatcherHostAgent(Integer clusterId, String hostnames) { } return Result.success(); } - + @Override public Result hostCheckCompleted(Integer clusterId) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); @@ -380,20 +385,20 @@ public Result hostCheckCompleted(Integer clusterId) { HostInfo value = hostInfoEntry.getValue(); if (Objects.isNull(value.getCheckResult()) || (Objects.nonNull(value.getCheckResult()) - && value.getCheckResult().getCode() != 10001)) { + && value.getCheckResult().getCode() != 10001)) { return Result.success().put("hostCheckCompleted", false); } } return Result.success().put("hostCheckCompleted", true); } - + @Override public Result cancelDispatcherHostAgent( - Integer clusterId, String hostname, Integer installStateCode) { - + Integer clusterId, String hostname, Integer installStateCode) { + return null; } - + @Override public Result dispatcherHostAgentCompleted(Integer clusterId) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); @@ -415,7 +420,7 @@ public Result dispatcherHostAgentCompleted(Integer clusterId) { } return Result.success().put("dispatcherHostAgentCompleted", true); } - + @Override public Result generateHostAgentCommand(String clusterHostIds, String commandType) throws Exception { if (StringUtils.isBlank(clusterHostIds)) { @@ -435,7 +440,7 @@ public Result generateHostAgentCommand(String clusterHostIds, String commandType } return Result.success(); } - + /** * 一键 启动 主机上安装的服务 * @@ -452,8 +457,9 @@ public Result generateHostServiceCommand(String clusterHostIds, String commandTy String[] clusterHostIdArray = clusterHostIds.split(Constants.COMMA); List clusterHostList = hostService.getHostListByIds(Arrays.asList(clusterHostIdArray)); Result result = null; - - CommandType serviceCommandType = "start".equalsIgnoreCase(commandType) ? CommandType.START_SERVICE : CommandType.STOP_SERVICE; + + CommandType serviceCommandType = + "start".equalsIgnoreCase(commandType) ? CommandType.START_SERVICE : CommandType.STOP_SERVICE; for (ClusterHostDO clusterHostDO : clusterHostList) { WorkerServiceMessage serviceMessage = new WorkerServiceMessage( clusterHostDO.getHostname(), clusterHostDO.getClusterId(), serviceCommandType); @@ -468,7 +474,7 @@ public Result generateHostServiceCommand(String clusterHostIds, String commandTy } return result == null ? Result.success() : result; } - + private List getListPage(List list, Integer offset, Integer pageSize) { List result = new ArrayList<>(); Integer limit = offset + pageSize; diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/NoticeGroupUserServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/NoticeGroupUserServiceImpl.java index 1e247f43..3809ce65 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/NoticeGroupUserServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/NoticeGroupUserServiceImpl.java @@ -17,15 +17,17 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.NoticeGroupUserService; import com.datasophon.dao.entity.NoticeGroupUserEntity; import com.datasophon.dao.mapper.NoticeGroupUserMapper; + import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("noticeGroupUserService") public class NoticeGroupUserServiceImpl extends ServiceImpl implements NoticeGroupUserService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/RoleInfoServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/RoleInfoServiceImpl.java index ee0f5841..1eb7669a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/RoleInfoServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/RoleInfoServiceImpl.java @@ -17,13 +17,15 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.RoleInfoService; import com.datasophon.dao.entity.RoleInfoEntity; import com.datasophon.dao.mapper.RoleInfoMapper; + import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("roleInfoService") public class RoleInfoServiceImpl extends ServiceImpl implements RoleInfoService { - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java index 126a5abb..0dda0844 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/ServiceInstallServiceImpl.java @@ -19,104 +19,147 @@ package com.datasophon.api.service.impl; -import cn.hutool.core.io.FileUtil; -import cn.hutool.crypto.SecureUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import static com.datasophon.common.Constants.META_PATH; + import com.datasophon.api.enums.Status; import com.datasophon.api.exceptions.ServiceException; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceConfigMap; import com.datasophon.api.load.ServiceInfoMap; import com.datasophon.api.load.ServiceRoleMap; -import com.datasophon.api.service.*; +import com.datasophon.api.service.ClusterInfoService; +import com.datasophon.api.service.ClusterServiceCommandHostCommandService; +import com.datasophon.api.service.ClusterServiceCommandService; +import com.datasophon.api.service.ClusterServiceInstanceConfigService; +import com.datasophon.api.service.ClusterServiceInstanceRoleGroupService; +import com.datasophon.api.service.ClusterServiceInstanceService; +import com.datasophon.api.service.ClusterServiceRoleGroupConfigService; +import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.ClusterVariableService; +import com.datasophon.api.service.FrameInfoService; +import com.datasophon.api.service.FrameServiceRoleService; +import com.datasophon.api.service.FrameServiceService; +import com.datasophon.api.service.ServiceInstallService; import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.api.strategy.ServiceRoleStrategy; import com.datasophon.api.strategy.ServiceRoleStrategyContext; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; -import com.datasophon.common.model.*; +import com.datasophon.common.model.DAG; +import com.datasophon.common.model.Generators; +import com.datasophon.common.model.HostServiceRoleMapping; +import com.datasophon.common.model.ServiceConfig; +import com.datasophon.common.model.ServiceInfo; +import com.datasophon.common.model.ServiceNode; +import com.datasophon.common.model.ServiceNodeEdge; +import com.datasophon.common.model.ServiceRoleHostMapping; +import com.datasophon.common.model.ServiceRoleInfo; import com.datasophon.common.utils.CollectionUtils; import com.datasophon.common.utils.PlaceholderUtils; import com.datasophon.common.utils.Result; -import com.datasophon.dao.entity.*; +import com.datasophon.dao.entity.ClusterHostDO; +import com.datasophon.dao.entity.ClusterInfoEntity; +import com.datasophon.dao.entity.ClusterServiceCommandEntity; +import com.datasophon.dao.entity.ClusterServiceCommandHostCommandEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceRoleGroup; +import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; +import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; +import com.datasophon.dao.entity.ClusterVariable; +import com.datasophon.dao.entity.FrameServiceEntity; +import com.datasophon.dao.entity.FrameServiceRoleEntity; import com.datasophon.dao.enums.NeedRestart; import com.datasophon.dao.enums.ServiceState; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang3.StringUtils; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; -import static com.datasophon.common.Constants.META_PATH; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.crypto.SecureUtil; @Service("serviceInstallService") @Transactional public class ServiceInstallServiceImpl implements ServiceInstallService { - + private static final Logger logger = LoggerFactory.getLogger(ServiceInstallServiceImpl.class); - + private static final List MUST_AT_SAME_NODE_BASIC_SERVICE = Arrays.asList("Grafana", "AlertManager", "Prometheus"); - + @Autowired private ClusterInfoService clusterInfoService; - + @Autowired FrameInfoService frameInfoService; - + @Autowired FrameServiceService frameService; - + @Autowired FrameServiceRoleService frameServiceRoleService; - + @Autowired ClusterServiceCommandService commandService; - + @Autowired private ClusterServiceInstanceService serviceInstanceService; - + @Autowired private ClusterServiceInstanceConfigService serviceInstanceConfigService; - + @Autowired private ClusterServiceCommandHostCommandService hostCommandService; - + @Autowired private ClusterVariableService variableService; - + @Autowired private ClusterHostService hostService; - + @Autowired private ClusterServiceInstanceRoleGroupService roleGroupService; - + @Autowired private ClusterServiceRoleGroupConfigService groupConfigService; - + @Autowired private ClusterServiceRoleInstanceService roleInstanceService; - + public static final String PROMETHEUS = "prometheus"; - + @Override public Result getServiceConfigOption(Integer clusterId, String serviceName) { List list = null; ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); - + Map globalVariables = GlobalVariables.get(clusterId); - + ClusterServiceInstanceEntity serviceInstance = serviceInstanceService.getServiceInstanceByClusterIdAndServiceName( clusterId, serviceName); @@ -130,23 +173,23 @@ public Result getServiceConfigOption(Integer clusterId, String serviceName) { serviceConfig = PlaceholderUtils.replacePlaceholders( serviceConfig, globalVariables, Constants.REGEX_VARIABLE); - + list = JSONArray.parseArray(serviceConfig, ServiceConfig.class); } - + ServiceRoleStrategy serviceRoleHandler = ServiceRoleStrategyContext.getServiceRoleHandler(serviceName); if (Objects.nonNull(serviceRoleHandler)) { serviceRoleHandler.getConfig(clusterId, list); } - + return Result.success(list); } - + @Override public Result saveServiceConfig( - Integer clusterId, String serviceName, List list, - Integer roleGroupId) { + Integer clusterId, String serviceName, List list, + Integer roleGroupId) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); ServiceConfigMap.put( clusterInfo.getClusterCode() + Constants.UNDERLINE + serviceName + Constants.CONFIG, @@ -240,12 +283,12 @@ public Result saveServiceConfig( } return Result.success(); } - + @Override public Result saveServiceRoleHostMapping(Integer clusterId, List list) { - + checkOnSameNode(clusterId, list); - + ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); String hostMapKey = clusterInfo.getClusterCode() @@ -255,12 +298,12 @@ public Result saveServiceRoleHostMapping(Integer clusterId, List>) CacheUtils.get(hostMapKey); } - + for (ServiceRoleHostMapping serviceRoleHostMapping : list) { serviceValidation(serviceRoleHostMapping); - + map.put(serviceRoleHostMapping.getServiceRole(), serviceRoleHostMapping.getHosts()); - + ServiceRoleStrategy serviceRoleHandler = ServiceRoleStrategyContext.getServiceRoleHandler( serviceRoleHostMapping.getServiceRole()); @@ -270,7 +313,7 @@ public Result saveServiceRoleHostMapping(Integer clusterId, List list) { ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); @@ -293,7 +336,7 @@ public Result saveHostServiceRoleMapping(Integer clusterId, List commandIds) { } return Result.success(); } - + @Override public void downloadPackage(String packageName, HttpServletResponse response) throws IOException { FileInputStream inputStream = null; OutputStream out = null; // 通过文件路径获得File对象 File file = new File(Constants.MASTER_MANAGE_PACKAGE_PATH + Constants.SLASH + packageName); - + inputStream = new FileInputStream(file); - + response.reset(); response.setContentType("application/octet-stream"); response.addHeader("Content-Length", "" + file.length()); @@ -381,16 +424,19 @@ public void downloadPackage(String packageName, HttpServletResponse response) th out.flush(); out.close(); } - + @Override - public void downloadResource(String frameCode, String serviceRoleName, String resource, HttpServletResponse response) throws IOException { + public void downloadResource(String frameCode, String serviceRoleName, String resource, + HttpServletResponse response) throws IOException { String metaPath = FileUtil.getAbsolutePath(META_PATH); - FrameServiceRoleEntity entity = frameServiceRoleService.getServiceRoleByFrameCodeAndServiceRoleName(frameCode, serviceRoleName); + FrameServiceRoleEntity entity = + frameServiceRoleService.getServiceRoleByFrameCodeAndServiceRoleName(frameCode, serviceRoleName); ServiceRoleInfo roleInfo = JSONObject.parseObject(entity.getServiceRoleJson(), ServiceRoleInfo.class); - + OutputStream out = null; // 通过文件路径获得File对象 - File file = new File(metaPath + Constants.SLASH + frameCode + Constants.SLASH + roleInfo.getParentName() + Constants.SLASH + resource); + File file = new File(metaPath + Constants.SLASH + frameCode + Constants.SLASH + roleInfo.getParentName() + + Constants.SLASH + resource); try (FileInputStream fis = new FileInputStream(file)) { response.reset(); response.setContentType("application/octet-stream"); @@ -410,12 +456,12 @@ public void downloadResource(String frameCode, String serviceRoleName, String re out.close(); } } - + @Override public Result getServiceRoleHostMapping(Integer clusterId) { return null; } - + @Override public Result checkServiceDependency(Integer clusterId, String serviceIds) { // @@ -428,7 +474,7 @@ public Result checkServiceDependency(Integer clusterId, String serviceIds) { ClusterServiceInstanceEntity::getServiceName, e -> e, (v1, v2) -> v1)); - + List list = frameService.listServices(serviceIds); Map serviceMap = list.stream() @@ -449,7 +495,7 @@ public Result checkServiceDependency(Integer clusterId, String serviceIds) { return Result.error( "service install depends on prometheus ,please make sure you have selected it or that prometheus is normal and running"); } - + for (FrameServiceEntity frameServiceEntity : list) { for (String dependService : frameServiceEntity.getDependencies().split(",")) { if (StringUtils.isNotBlank(dependService) @@ -468,9 +514,9 @@ public Result checkServiceDependency(Integer clusterId, String serviceIds) { } return Result.success(); } - + private ClusterServiceInstanceRoleGroup saveNewRoleGroup( - ClusterServiceInstanceEntity serviceInstanceEntity) { + ClusterServiceInstanceEntity serviceInstanceEntity) { int count = roleGroupService.count( new QueryWrapper() @@ -486,9 +532,9 @@ private ClusterServiceInstanceRoleGroup saveNewRoleGroup( roleGroupService.save(roleGroup); return roleGroup; } - + private boolean isConfigNeedUpdate( - ClusterServiceInstanceEntity serviceInstanceEntity, List list) { + ClusterServiceInstanceEntity serviceInstanceEntity, List list) { List originalConfigs = listServiceConfigByServiceInstance(serviceInstanceEntity); Map originalConfigMap = @@ -512,13 +558,13 @@ private boolean isConfigNeedUpdate( } return false; } - + private void saveServiceRoleGroupConfig( - Integer clusterId, - String serviceName, - List list, - HashMap> configFileMap, - ClusterServiceInstanceRoleGroup clusterServiceInstanceRoleGroup) { + Integer clusterId, + String serviceName, + List list, + HashMap> configFileMap, + ClusterServiceInstanceRoleGroup clusterServiceInstanceRoleGroup) { ClusterServiceRoleGroupConfig roleGroupConfig = new ClusterServiceRoleGroupConfig(); roleGroupConfig.setRoleGroupId(clusterServiceInstanceRoleGroup.getId()); roleGroupConfig.setClusterId(clusterId); @@ -529,11 +575,11 @@ private void saveServiceRoleGroupConfig( roleGroupConfig.setConfigVersion(1); groupConfigService.save(roleGroupConfig); } - + private ClusterServiceInstanceRoleGroup saveServiceInstanceRoleGroup( - Integer clusterId, - String serviceName, - ClusterServiceInstanceEntity serviceInstanceEntity) { + Integer clusterId, + String serviceName, + ClusterServiceInstanceEntity serviceInstanceEntity) { ClusterServiceInstanceRoleGroup clusterServiceInstanceRoleGroup = new ClusterServiceInstanceRoleGroup(); clusterServiceInstanceRoleGroup.setServiceInstanceId(serviceInstanceEntity.getId()); @@ -544,10 +590,10 @@ private ClusterServiceInstanceRoleGroup saveServiceInstanceRoleGroup( roleGroupService.save(clusterServiceInstanceRoleGroup); return clusterServiceInstanceRoleGroup; } - + private ClusterServiceInstanceEntity saveServiceInstance( - Integer clusterId, String serviceName, - FrameServiceEntity frameServiceEntity) { + Integer clusterId, String serviceName, + FrameServiceEntity frameServiceEntity) { ClusterServiceInstanceEntity serviceInstanceEntity; serviceInstanceEntity = new ClusterServiceInstanceEntity(); serviceInstanceEntity.setClusterId(clusterId); @@ -562,9 +608,9 @@ private ClusterServiceInstanceEntity saveServiceInstance( serviceInstanceService.save(serviceInstanceEntity); return serviceInstanceEntity; } - + private void addHostNodeToPrometheus( - Integer clusterId, HashMap> configFileMap) { + Integer clusterId, HashMap> configFileMap) { List hostList = hostService.list( new QueryWrapper() @@ -575,7 +621,7 @@ private void addHostNodeToPrometheus( workerGenerators.setOutputDirectory("configs"); workerGenerators.setConfigFormat("custom"); workerGenerators.setTemplateName("scrape.ftl"); - + Generators nodeGenerators = new Generators(); nodeGenerators.setFilename("linux.json"); nodeGenerators.setOutputDirectory("configs"); @@ -589,7 +635,7 @@ private void addHostNodeToPrometheus( serviceConfig.setValue(clusterHostDO.getHostname() + ":8585"); serviceConfig.setRequired(true); workerServiceConfigs.add(serviceConfig); - + ServiceConfig nodeServiceConfig = new ServiceConfig(); nodeServiceConfig.setName("node_" + clusterHostDO.getHostname()); nodeServiceConfig.setValue(clusterHostDO.getHostname() + ":9100"); @@ -599,12 +645,12 @@ private void addHostNodeToPrometheus( configFileMap.put(workerGenerators, workerServiceConfigs); configFileMap.put(nodeGenerators, nodeServiceConfigs); } - + private void buildConfigFileMap( - String serviceName, - ClusterInfoEntity clusterInfo, - HashMap map, - HashMap> configFileMap) { + String serviceName, + ClusterInfoEntity clusterInfo, + HashMap map, + HashMap> configFileMap) { FrameServiceEntity frameService = this.frameService.getServiceByFrameCodeAndServiceName( clusterInfo.getClusterFrame(), serviceName); @@ -628,7 +674,7 @@ private void buildConfigFileMap( } } } - + private void addToGlobalVariable(Integer clusterId, String serviceName, String variableName, String value) { ClusterVariable clusterVariable = variableService.getVariableByVariableName(variableName, clusterId); @@ -647,11 +693,11 @@ private void addToGlobalVariable(Integer clusterId, String serviceName, String v variableService.save(clusterVariable); } } - + private void buildConfig( - List list, - HashMap> configFileMap, - ClusterServiceRoleGroupConfig roleGroupConfig) { + List list, + HashMap> configFileMap, + ClusterServiceRoleGroupConfig roleGroupConfig) { String configJson = JSONObject.toJSONString(list); String configFileJson = JSONObject.toJSONString(configFileMap); roleGroupConfig.setConfigJson(configJson); @@ -659,7 +705,7 @@ private void buildConfig( roleGroupConfig.setConfigFileJson(configFileJson); roleGroupConfig.setConfigFileJsonMd5(SecureUtil.md5(configFileJson)); } - + private void checkOnSameNode(Integer clusterId, List list) { Set hostnameSet = list.stream() @@ -670,7 +716,7 @@ private void checkOnSameNode(Integer clusterId, List lis if (CollectionUtils.isEmpty(hostnameSet)) { return; } - + Set installedHostnameSet = roleInstanceService.lambdaQuery() .eq(ClusterServiceRoleInstanceEntity::getClusterId, clusterId) @@ -681,16 +727,16 @@ private void checkOnSameNode(Integer clusterId, List lis .map(ClusterServiceRoleInstanceEntity::getHostname) .collect(Collectors.toSet()); hostnameSet.addAll(installedHostnameSet); - + if (hostnameSet.size() > 1) { throw new ServiceException(Status.BASIC_SERVICE_SELECT_MOST_ONE_HOST.getMsg()); } } - + private void serviceValidation(ServiceRoleHostMapping serviceRoleHostMapping) { String serviceRole = serviceRoleHostMapping.getServiceRole(); List hosts = serviceRoleHostMapping.getHosts(); - + if ("JournalNode".equals(serviceRole) && hosts.size() != 3) { throw new ServiceException(Status.THREE_JOURNALNODE_DEPLOYMENTS_REQUIRED.getMsg()); } @@ -713,9 +759,9 @@ private void serviceValidation(ServiceRoleHostMapping serviceRoleHostMapping) { throw new ServiceException(Status.TWO_KYUUBISERVERS_NEED_TO_BE_DEPLOYED.getMsg()); } } - + private List listServiceConfigByServiceInstance( - ClusterServiceInstanceEntity serviceInstance) { + ClusterServiceInstanceEntity serviceInstance) { ClusterServiceInstanceRoleGroup roleGroup = roleGroupService.getRoleGroupByServiceInstanceId(serviceInstance.getId()); ClusterServiceRoleGroupConfig config = diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/SessionServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/SessionServiceImpl.java index 780d7f6f..7f7bcd31 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/SessionServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/SessionServiceImpl.java @@ -17,15 +17,22 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.service.SessionService; import com.datasophon.api.utils.HttpUtils; import com.datasophon.common.Constants; import com.datasophon.dao.entity.SessionEntity; import com.datasophon.dao.entity.UserInfoEntity; import com.datasophon.dao.mapper.SessionMapper; -import org.apache.commons.lang.StringUtils; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,20 +40,17 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.util.WebUtils; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import java.util.Date; -import java.util.List; -import java.util.UUID; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service("sessionService") public class SessionServiceImpl extends ServiceImpl implements SessionService { - + private static final Logger logger = LoggerFactory.getLogger(SessionService.class); - + @Autowired private SessionMapper sessionMapper; - + /** * get user session from request * @@ -56,25 +60,25 @@ public class SessionServiceImpl extends ServiceImpl sessionList = sessionMapper.queryByUserId(user.getId()); - + Date now = new Date(); - + /** * if you have logged in and are still valid, return directly */ @@ -109,9 +113,9 @@ public String createSession(UserInfoEntity user, String ip) { */ session.setLastLoginTime(now); sessionMapper.updateById(session); - + return session.getId(); - + } else { /** * session expired, then delete this session first @@ -119,20 +123,20 @@ public String createSession(UserInfoEntity user, String ip) { sessionMapper.deleteById(session.getId()); } } - + // assign new session session = new SessionEntity(); - + session.setId(UUID.randomUUID().toString()); session.setIp(ip); session.setUserId(user.getId()); session.setLastLoginTime(now); - + sessionMapper.insertSession(session); - + return session.getId(); } - + /** * sign out * remove ip restrictions @@ -147,12 +151,12 @@ public void signOut(String ip, UserInfoEntity loginUser) { * query session by user id and ip */ SessionEntity session = sessionMapper.queryByUserIdAndIp(loginUser.getId(), ip); - + // delete session sessionMapper.deleteById(session.getId()); } catch (Exception e) { logger.warn("userId : {} , ip : {} , find more one session", loginUser.getId(), ip); } } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/service/impl/UserInfoServiceImpl.java b/datasophon-service/src/main/java/com/datasophon/api/service/impl/UserInfoServiceImpl.java index 217da6b9..c6ee1777 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/service/impl/UserInfoServiceImpl.java +++ b/datasophon-service/src/main/java/com/datasophon/api/service/impl/UserInfoServiceImpl.java @@ -17,8 +17,6 @@ package com.datasophon.api.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.datasophon.api.enums.Status; import com.datasophon.api.service.UserInfoService; import com.datasophon.api.utils.CheckUtils; @@ -27,20 +25,25 @@ import com.datasophon.common.utils.Result; import com.datasophon.dao.entity.UserInfoEntity; import com.datasophon.dao.mapper.UserInfoMapper; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; + +import org.apache.commons.lang3.StringUtils; import java.util.Date; import java.util.List; import java.util.Objects; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + @Service("userInfoService") public class UserInfoServiceImpl extends ServiceImpl implements UserInfoService { - + @Autowired private UserInfoMapper userMapper; - + @Override public UserInfoEntity queryUser(String username, String password) { String md5 = EncryptionUtils.getMd5(password); @@ -48,7 +51,7 @@ public UserInfoEntity queryUser(String username, String password) { .eq(Constants.USERNAME, username) .eq(Constants.PASSWORD, md5)); } - + @Override public Result createUser(UserInfoEntity userInfo) { // check all user params @@ -72,7 +75,7 @@ public Result createUser(UserInfoEntity userInfo) { this.save(userInfo); return Result.success(); } - + /** * @param userName * @param password @@ -81,25 +84,25 @@ public Result createUser(UserInfoEntity userInfo) { * @return if check failed return the field, otherwise return null */ private String checkUserParams(String userName, String password, String email, String phone) { - + String msg = null; if (!CheckUtils.checkUserName(userName)) { - + msg = userName; } else if (!CheckUtils.checkPassword(password)) { - + msg = password; } else if (!CheckUtils.checkEmail(email)) { - + msg = email; } else if (!CheckUtils.checkPhone(phone)) { - + msg = phone; } - + return msg; } - + @Override public Result getUserListByPage(String username, Integer page, Integer pageSize) { Integer offset = (page - 1) * pageSize; diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/AlertManagerHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/AlertManagerHandlerStrategy.java index 68f741f3..31c1d874 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/AlertManagerHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/AlertManagerHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.api.strategy; -import cn.hutool.http.HttpUtil; import com.datasophon.api.utils.ProcessUtils; import com.datasophon.common.model.ServiceConfig; import com.datasophon.common.model.ServiceRoleInfo; @@ -27,28 +26,30 @@ import java.util.List; import java.util.Map; -public class AlertManagerHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.http.HttpUtil; +public class AlertManagerHandlerStrategy implements ServiceRoleStrategy { + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { @@ -60,7 +61,7 @@ public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanc // save alert String alertTargetName = roleInstanceEntity.getServiceRoleName() + " Survive"; ProcessUtils.saveAlert(roleInstanceEntity, alertTargetName, AlertLevel.EXCEPTION, "restart"); - + } } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/BEHandlerStartegy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/BEHandlerStartegy.java index 71fedef7..af7acce9 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/BEHandlerStartegy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/BEHandlerStartegy.java @@ -26,31 +26,32 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; import com.datasophon.dao.enums.ServiceRoleState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; -public class BEHandlerStartegy implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +public class BEHandlerStartegy implements ServiceRoleStrategy { + private static final Logger logger = LoggerFactory.getLogger(BEHandlerStartegy.class); - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { Map globalVariables = GlobalVariables.get(serviceRoleInfo.getClusterId()); @@ -58,7 +59,7 @@ public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostn logger.info("fe master is {}", feMaster); serviceRoleInfo.setMasterHost(feMaster); } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { @@ -70,13 +71,13 @@ public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanc List backends = OlapUtils.showBackends(feMaster); resolveProcInfoAlert(roleInstanceEntity.getServiceRoleName(), backends, map); } catch (Exception e) { - + } - + } - + } - + private void resolveProcInfoAlert(String serviceRoleName, List frontends, Map map) { for (ProcInfo frontend : frontends) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/ElasticSearchHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/ElasticSearchHandlerStrategy.java index d4be8a93..2bca0858 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/ElasticSearchHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/ElasticSearchHandlerStrategy.java @@ -17,9 +17,6 @@ package com.datasophon.api.strategy; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceInfoMap; import com.datasophon.api.load.ServiceRoleMap; @@ -34,6 +31,7 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -43,48 +41,53 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -public class ElasticSearchHandlerStrategy implements ServiceRoleStrategy { +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class ElasticSearchHandlerStrategy implements ServiceRoleStrategy { + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); - - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${initMasterNodes}", String.join(",", hosts)); + + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${initMasterNodes}", + String.join(",", hosts)); String join = String.join(":9300,", hosts); String seedHosts = join + ":9300"; - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${seedHosts}", seedHosts); - + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${seedHosts}", seedHosts); + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { Integer clusterId = roleInstanceEntity.getClusterId(); - + ClusterInfoEntity cluster = ProcessUtils.getClusterInfo(clusterId); String frameCode = cluster.getClusterFrame(); - + String key = frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName() + Constants.UNDERLINE + roleInstanceEntity.getServiceRoleName(); ServiceRoleInfo serviceRoleInfo = ServiceRoleMap.get(key); ServiceInfo serviceInfo = ServiceInfoMap.get(frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName()); - + ActorSelection execCmdActor = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + roleInstanceEntity.getHostname() + ":2552/user/worker/executeCmdActor"); ExecuteCmdCommand cmdCommand = new ExecuteCmdCommand(); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/FEHandlerStartegy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/FEHandlerStartegy.java index ea91ba32..5f653a17 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/FEHandlerStartegy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/FEHandlerStartegy.java @@ -17,7 +17,6 @@ package com.datasophon.api.strategy; -import cn.hutool.core.util.ObjUtil; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.utils.ProcessUtils; import com.datasophon.common.model.ProcInfo; @@ -27,38 +26,42 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; import com.datasophon.dao.enums.ServiceRoleState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; -public class FEHandlerStartegy implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(FEHandlerStartegy.class); +import cn.hutool.core.util.ObjUtil; +public class FEHandlerStartegy implements ServiceRoleStrategy { + + private static final Logger logger = LoggerFactory.getLogger(FEHandlerStartegy.class); + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); // if feMaster is null, set the first host as feMaster - //Prevent FE Observer nodes from starting and FE Master nodes from changing + // Prevent FE Observer nodes from starting and FE Master nodes from changing if (!globalVariables.containsKey("${feMaster}") || ObjUtil.isNull(globalVariables.get("${feMaster}"))) { if (!hosts.isEmpty()) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${feMaster}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${feMaster}", + hosts.get(0)); } } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { Map globalVariables = GlobalVariables.get(serviceRoleInfo.getClusterId()); @@ -72,9 +75,9 @@ public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostn serviceRoleInfo.setSlave(true); serviceRoleInfo.setSortNum(2); } - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { @@ -86,12 +89,12 @@ public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanc List frontends = OlapUtils.showFrontends(feMaster); resolveProcInfoAlert(roleInstanceEntity.getServiceRoleName(), frontends, map); } catch (Exception e) { - + } - - + } } + private void resolveProcInfoAlert(String serviceRoleName, List frontends, Map map) { for (ProcInfo frontend : frontends) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/FEObserverHandlerStartegy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/FEObserverHandlerStartegy.java index b5dc4cff..2a935a7d 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/FEObserverHandlerStartegy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/FEObserverHandlerStartegy.java @@ -26,31 +26,32 @@ import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; import com.datasophon.dao.enums.ServiceRoleState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; -public class FEObserverHandlerStartegy implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +public class FEObserverHandlerStartegy implements ServiceRoleStrategy { + private static final Logger logger = LoggerFactory.getLogger(FEObserverHandlerStartegy.class); - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { Map globalVariables = GlobalVariables.get(serviceRoleInfo.getClusterId()); @@ -64,9 +65,9 @@ public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostn serviceRoleInfo.setSlave(true); serviceRoleInfo.setSortNum(2); } - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { @@ -78,12 +79,12 @@ public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanc List frontends = OlapUtils.showFrontends(feMaster); resolveProcInfoAlert(roleInstanceEntity.getServiceRoleName(), frontends, map); } catch (Exception e) { - + } - - + } } + private void resolveProcInfoAlert(String serviceRoleName, List frontends, Map map) { for (ProcInfo frontend : frontends) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/FlinkHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/FlinkHandlerStrategy.java index a533aef8..fc4cb88f 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/FlinkHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/FlinkHandlerStrategy.java @@ -31,12 +31,12 @@ import java.util.Map; public class FlinkHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); @@ -49,7 +49,7 @@ public void handlerConfig(Integer clusterId, List list, String se enableKerberos = isEnableKerberos(clusterId, globalVariables, enableKerberos, serviceConfig, "FLINK"); } } - + for (ServiceConfig config : list) { if ("enableJMHA".equals(config.getName())) { enableJM2HA = isEnableHA(clusterId, globalVariables, enableJM2HA, config, "FLINK"); @@ -63,31 +63,31 @@ public void handlerConfig(Integer clusterId, List list, String se } else { removeConfigWithHA(list, map, configs); } - + ArrayList kbConfigs = new ArrayList<>(); if (enableKerberos) { addConfigWithKerberos(globalVariables, map, configs, kbConfigs); } else { removeConfigWithKerberos(list, map, configs); } - + list.addAll(haConfigs); list.addAll(kbConfigs); } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/GrafanaHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/GrafanaHandlerStrategy.java index d66ebc98..a90cda94 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/GrafanaHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/GrafanaHandlerStrategy.java @@ -28,34 +28,34 @@ import java.util.Map; public class GrafanaHandlerStrategy implements ServiceRoleStrategy { - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() == 1) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${grafanaHost}", + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${grafanaHost}", HostUtils.getIp(hosts.get(0))); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/HBaseHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/HBaseHandlerStrategy.java index 96afe0b3..2c44ff10 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/HBaseHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/HBaseHandlerStrategy.java @@ -31,12 +31,12 @@ import java.util.Map; public class HBaseHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); @@ -58,20 +58,20 @@ public void handlerConfig(Integer clusterId, List list, String se } list.addAll(kbConfigs); } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/HistoryServerHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/HistoryServerHandlerStrategy.java index 48f693ea..3f4090b5 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/HistoryServerHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/HistoryServerHandlerStrategy.java @@ -27,33 +27,34 @@ import java.util.Map; public class HistoryServerHandlerStrategy implements ServiceRoleStrategy { - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() == 1) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${historyserverHost}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${historyserverHost}", + hosts.get(0)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveMetaStroreHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveMetaStroreHandlerStrategy.java index 80c657c3..9b071ee2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveMetaStroreHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveMetaStroreHandlerStrategy.java @@ -27,33 +27,34 @@ import java.util.Map; public class HiveMetaStroreHandlerStrategy implements ServiceRoleStrategy { - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() == 1) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${metastoreHost}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${metastoreHost}", + hosts.get(0)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveServer2HandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveServer2HandlerStrategy.java index e831f867..943aaa7f 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveServer2HandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/HiveServer2HandlerStrategy.java @@ -27,15 +27,16 @@ import com.datasophon.common.utils.PlaceholderUtils; import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; import java.util.Map; -public class HiveServer2HandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +public class HiveServer2HandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { + private static final Logger logger = LoggerFactory.getLogger(HiveServer2HandlerStrategy.class); @Override public void handler(Integer clusterId, List hosts, String serviceName) { @@ -43,10 +44,11 @@ public void handler(Integer clusterId, List hosts, String serviceName) { CacheUtils.put("enableHiveServer2HA", false); if (hosts.size() > 1) { CacheUtils.put("enableHiveServer2HA", true); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${masterHiveServer2}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${masterHiveServer2}", + hosts.get(0)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); @@ -57,7 +59,7 @@ public void handlerConfig(Integer clusterId, List list, String se if ("enableKerberos".equals(config.getName())) { enableKerberos = isEnableKerberos(clusterId, globalVariables, enableKerberos, config, "HIVE"); } - + } String key = clusterInfo.getClusterFrame() + Constants.UNDERLINE + "HIVE" + Constants.CONFIG; List configs = ServiceConfigMap.get(key); @@ -68,9 +70,9 @@ public void handlerConfig(Integer clusterId, List list, String se removeConfigWithKerberos(list, map, configs); } list.addAll(kbConfigs); - + } - + @Override public void getConfig(Integer clusterId, List list) { // if enabled hiveserver2 ha @@ -100,7 +102,7 @@ public void getConfig(Integer clusterId, List list) { } } } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { Map globalVariables = GlobalVariables.get(serviceRoleInfo.getClusterId()); @@ -110,10 +112,10 @@ public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostn serviceRoleInfo.setSlave(true); } } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/HttpFsHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/HttpFsHandlerStrategy.java index 15fc7fef..023acb41 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/HttpFsHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/HttpFsHandlerStrategy.java @@ -1,6 +1,5 @@ package com.datasophon.api.strategy; -import cn.hutool.core.collection.CollUtil; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.utils.ProcessUtils; import com.datasophon.common.model.ServiceConfig; @@ -10,33 +9,36 @@ import java.util.List; import java.util.Map; -public class HttpFsHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.collection.CollUtil; +public class HttpFsHandlerStrategy implements ServiceRoleStrategy { + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (CollUtil.isNotEmpty(hosts)) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${httpFs}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${httpFs}", hosts.get(0)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override - public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, + Map map) { + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/JournalNodeHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/JournalNodeHandlerStrategy.java index ad11f98b..79a6d137 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/JournalNodeHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/JournalNodeHandlerStrategy.java @@ -27,35 +27,38 @@ import java.util.Map; public class JournalNodeHandlerStrategy implements ServiceRoleStrategy { - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() >= 3) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${journalNode1}", hosts.get(0)); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${journalNode2}", hosts.get(1)); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${journalNode3}", hosts.get(2)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${journalNode1}", + hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${journalNode2}", + hosts.get(1)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${journalNode3}", + hosts.get(2)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/KAdminHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/KAdminHandlerStrategy.java index d79bba5a..db2d81f3 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/KAdminHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/KAdminHandlerStrategy.java @@ -17,9 +17,6 @@ package com.datasophon.api.strategy; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceInfoMap; import com.datasophon.api.load.ServiceRoleMap; @@ -34,6 +31,7 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -43,45 +41,50 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -public class KAdminHandlerStrategy implements ServiceRoleStrategy { +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class KAdminHandlerStrategy implements ServiceRoleStrategy { + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() >= 1) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${kadminHost}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${kadminHost}", + hosts.get(0)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { Integer clusterId = roleInstanceEntity.getClusterId(); - + ClusterInfoEntity cluster = ProcessUtils.getClusterInfo(clusterId); String frameCode = cluster.getClusterFrame(); - + String key = frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName() + Constants.UNDERLINE + roleInstanceEntity.getServiceRoleName(); ServiceRoleInfo serviceRoleInfo = ServiceRoleMap.get(key); ServiceInfo serviceInfo = ServiceInfoMap.get(frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName()); - + ActorSelection execCmdActor = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + roleInstanceEntity.getHostname() + ":2552/user/worker/executeCmdActor"); ExecuteCmdCommand cmdCommand = new ExecuteCmdCommand(); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/KafkaHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/KafkaHandlerStrategy.java index ee942ce8..fe817f61 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/KafkaHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/KafkaHandlerStrategy.java @@ -31,12 +31,12 @@ import java.util.Map; public class KafkaHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); @@ -58,20 +58,20 @@ public void handlerConfig(Integer clusterId, List list, String se } list.addAll(kbConfigs); } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/KerberosHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/KerberosHandlerStrategy.java index c86c93c5..8f334f36 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/KerberosHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/KerberosHandlerStrategy.java @@ -17,9 +17,6 @@ package com.datasophon.api.strategy; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.ServiceInfoMap; import com.datasophon.api.load.ServiceRoleMap; import com.datasophon.api.master.ActorUtils; @@ -33,6 +30,7 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -42,42 +40,46 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -public class KerberosHandlerStrategy implements ServiceRoleStrategy { +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class KerberosHandlerStrategy implements ServiceRoleStrategy { + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { Integer clusterId = roleInstanceEntity.getClusterId(); - + ClusterInfoEntity cluster = ProcessUtils.getClusterInfo(clusterId); String frameCode = cluster.getClusterFrame(); - + String key = frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName() + Constants.UNDERLINE + roleInstanceEntity.getServiceRoleName(); ServiceRoleInfo serviceRoleInfo = ServiceRoleMap.get(key); ServiceInfo serviceInfo = ServiceInfoMap.get(frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName()); - + ActorSelection execCmdActor = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + roleInstanceEntity.getHostname() + ":2552/user/worker/executeCmdActor"); ExecuteCmdCommand cmdCommand = new ExecuteCmdCommand(); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/Krb5KdcHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/Krb5KdcHandlerStrategy.java index 5f23c645..f40f854c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/Krb5KdcHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/Krb5KdcHandlerStrategy.java @@ -17,9 +17,6 @@ package com.datasophon.api.strategy; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceInfoMap; import com.datasophon.api.load.ServiceRoleMap; @@ -34,6 +31,7 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -43,45 +41,49 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -public class Krb5KdcHandlerStrategy implements ServiceRoleStrategy { +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class Krb5KdcHandlerStrategy implements ServiceRoleStrategy { + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() >= 1) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${kdcHost}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${kdcHost}", hosts.get(0)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { Integer clusterId = roleInstanceEntity.getClusterId(); - + ClusterInfoEntity cluster = ProcessUtils.getClusterInfo(clusterId); String frameCode = cluster.getClusterFrame(); - + String key = frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName() + Constants.UNDERLINE + roleInstanceEntity.getServiceRoleName(); ServiceRoleInfo serviceRoleInfo = ServiceRoleMap.get(key); ServiceInfo serviceInfo = ServiceInfoMap.get(frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName()); - + ActorSelection execCmdActor = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + roleInstanceEntity.getHostname() + ":2552/user/worker/executeCmdActor"); ExecuteCmdCommand cmdCommand = new ExecuteCmdCommand(); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/KyuubiServerHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/KyuubiServerHandlerStrategy.java index 4a7f0f16..e1674b8a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/KyuubiServerHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/KyuubiServerHandlerStrategy.java @@ -27,63 +27,63 @@ import com.datasophon.common.model.ServiceRoleInfo; import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class KyuubiServerHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy{ - - private static final Logger logger = LoggerFactory.getLogger(KyuubiServerHandlerStrategy.class); - private static final String ENABLE_KERBEROS = "enableKerberos"; - - @Override - public void handler(Integer clusterId, List hosts, String serviceName) { - - } - - @Override - public void handlerConfig(Integer clusterId, List list, String serviceName) { - - Map globalVariables = GlobalVariables.get(clusterId); - boolean enableKerberos = false; - Map map = ProcessUtils.translateToMap(list); - ClusterInfoEntity clusterInfo = ProcessUtils.getClusterInfo(clusterId); - // todo: 判断kerberos的逻辑应该抽取到公共方法中 - for (ServiceConfig config : list) { - if (ENABLE_KERBEROS.equals(config.getName())) { - enableKerberos = - isEnableKerberos( - clusterId, globalVariables, enableKerberos, config, "KYUUBI"); - } +public class KyuubiServerHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { + + private static final Logger logger = LoggerFactory.getLogger(KyuubiServerHandlerStrategy.class); + private static final String ENABLE_KERBEROS = "enableKerberos"; + + @Override + public void handler(Integer clusterId, List hosts, String serviceName) { + } - String key = clusterInfo.getClusterFrame() + Constants.UNDERLINE + "KYUUBI" + Constants.CONFIG; - List configs = ServiceConfigMap.get(key); - ArrayList kbConfigs = new ArrayList<>(); - if (enableKerberos) { - addConfigWithKerberos(globalVariables, map, configs, kbConfigs); - } else { - removeConfigWithKerberos(list, map, configs); + + @Override + public void handlerConfig(Integer clusterId, List list, String serviceName) { + + Map globalVariables = GlobalVariables.get(clusterId); + boolean enableKerberos = false; + Map map = ProcessUtils.translateToMap(list); + ClusterInfoEntity clusterInfo = ProcessUtils.getClusterInfo(clusterId); + // todo: 判断kerberos的逻辑应该抽取到公共方法中 + for (ServiceConfig config : list) { + if (ENABLE_KERBEROS.equals(config.getName())) { + enableKerberos = + isEnableKerberos( + clusterId, globalVariables, enableKerberos, config, "KYUUBI"); + } + } + String key = clusterInfo.getClusterFrame() + Constants.UNDERLINE + "KYUUBI" + Constants.CONFIG; + List configs = ServiceConfigMap.get(key); + ArrayList kbConfigs = new ArrayList<>(); + if (enableKerberos) { + addConfigWithKerberos(globalVariables, map, configs, kbConfigs); + } else { + removeConfigWithKerberos(list, map, configs); + } + list.addAll(kbConfigs); } - list.addAll(kbConfigs); - } - - @Override - public void getConfig(Integer clusterId, List list) { - - } - - @Override - public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - - } - - @Override - public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, - Map map) { - } - + + @Override + public void getConfig(Integer clusterId, List list) { + + } + + @Override + public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { + + } + + @Override + public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, + Map map) { + } + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/NameNodeHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/NameNodeHandlerStrategy.java index e0ed49f9..ff0769aa 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/NameNodeHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/NameNodeHandlerStrategy.java @@ -19,9 +19,6 @@ package com.datasophon.api.strategy; -import akka.actor.ActorRef; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceConfigMap; import com.datasophon.api.master.ActorUtils; @@ -35,8 +32,7 @@ import com.datasophon.common.utils.ExecResult; import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -46,38 +42,45 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -public class NameNodeHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(NameNodeHandlerStrategy.class); +import akka.actor.ActorRef; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class NameNodeHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { + + private static final Logger logger = LoggerFactory.getLogger(NameNodeHandlerStrategy.class); + private static final String ENABLE_RACK = "enableRack"; - + private static final String ENABLE_KERBEROS = "enableKerberos"; - + private static final String ACTIVE = "active"; - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + Map globalVariables = GlobalVariables.get(clusterId); - - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${nn1}", hosts.get(0)); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${nn2}", hosts.get(1)); + + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${nn1}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${nn2}", hosts.get(1)); } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); ClusterInfoEntity clusterInfo = ProcessUtils.getClusterInfo(clusterId); - + boolean enableRack = false; boolean enableKerberos = false; Map map = ProcessUtils.translateToMap(list); - + String key = clusterInfo.getClusterFrame() + Constants.UNDERLINE + "HDFS" + Constants.CONFIG; List configs = ServiceConfigMap.get(key); - + for (ServiceConfig config : list) { if (ENABLE_RACK.equals(config.getName())) { if ((Boolean) config.getValue()) { @@ -98,7 +101,7 @@ public void handlerConfig(Integer clusterId, List list, String se removeConfigWithRack(list, map, configs); } list.addAll(rackConfigs); - + ArrayList kbConfigs = new ArrayList<>(); if (enableKerberos) { addConfigWithKerberos(globalVariables, map, configs, kbConfigs); @@ -107,11 +110,11 @@ public void handlerConfig(Integer clusterId, List list, String se } list.addAll(kbConfigs); } - + @Override public void getConfig(Integer clusterId, List list) { } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { Map globalVariables = GlobalVariables.get(serviceRoleInfo.getClusterId()); @@ -121,11 +124,11 @@ public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostn serviceRoleInfo.setSortNum(5); } } - + @Override public void handlerServiceRoleCheck( - ClusterServiceRoleInstanceEntity roleInstanceEntity, - Map map) { + ClusterServiceRoleInstanceEntity roleInstanceEntity, + Map map) { Map globalVariable = GlobalVariables.get(roleInstanceEntity.getClusterId()); String nn2 = globalVariable.get("${nn2}"); String commandLine = @@ -136,9 +139,9 @@ public void handlerServiceRoleCheck( } getNMState(roleInstanceEntity, commandLine); } - + private void getNMState( - ClusterServiceRoleInstanceEntity roleInstanceEntity, String commandLine) { + ClusterServiceRoleInstanceEntity roleInstanceEntity, String commandLine) { ClusterServiceRoleInstanceWebuisService webuisService = SpringTool.getApplicationContext() .getBean(ClusterServiceRoleInstanceWebuisService.class); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/PrometheusHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/PrometheusHandlerStrategy.java index 6e3e5028..aaa0a7b8 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/PrometheusHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/PrometheusHandlerStrategy.java @@ -17,9 +17,6 @@ package com.datasophon.api.strategy; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.ServiceInfoMap; import com.datasophon.api.load.ServiceRoleMap; import com.datasophon.api.master.ActorUtils; @@ -33,6 +30,7 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.enums.AlertLevel; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -42,42 +40,46 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -public class PrometheusHandlerStrategy implements ServiceRoleStrategy { +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class PrometheusHandlerStrategy implements ServiceRoleStrategy { + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { Integer clusterId = roleInstanceEntity.getClusterId(); - + ClusterInfoEntity cluster = ProcessUtils.getClusterInfo(clusterId); String frameCode = cluster.getClusterFrame(); - + String key = frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName() + Constants.UNDERLINE + roleInstanceEntity.getServiceRoleName(); ServiceRoleInfo serviceRoleInfo = ServiceRoleMap.get(key); ServiceInfo serviceInfo = ServiceInfoMap.get(frameCode + Constants.UNDERLINE + roleInstanceEntity.getServiceName()); - + ActorSelection execCmdActor = ActorUtils.actorSystem.actorSelection( "akka.tcp://datasophon@" + roleInstanceEntity.getHostname() + ":2552/user/worker/executeCmdActor"); ExecuteCmdCommand cmdCommand = new ExecuteCmdCommand(); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/RMHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/RMHandlerStrategy.java index 5427c255..40a7da84 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/RMHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/RMHandlerStrategy.java @@ -19,9 +19,6 @@ package com.datasophon.api.strategy; -import akka.actor.ActorRef; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceConfigMap; import com.datasophon.api.master.ActorUtils; @@ -37,9 +34,9 @@ import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; import com.datasophon.dao.entity.ClusterYarnScheduler; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -49,23 +46,30 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -public class RMHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(RMHandlerStrategy.class); +import akka.actor.ActorRef; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class RMHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { + + private static final Logger logger = LoggerFactory.getLogger(RMHandlerStrategy.class); + private static final String ACTIVE = "active"; - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { - + Map globalVariables = GlobalVariables.get(clusterId); - + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${rm1}", hosts.get(0)); ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${rm2}", hosts.get(1)); ProcessUtils.generateClusterVariable( globalVariables, clusterId, serviceName, "${rmHost}", String.join(",", hosts)); } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { ClusterYarnSchedulerService schedulerService = @@ -107,32 +111,32 @@ public void handlerConfig(Integer clusterId, List list, String se } list.addAll(kbConfigs); } - + @Override public void getConfig(Integer clusterId, List list) { } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { } - + @Override public void handlerServiceRoleCheck( - ClusterServiceRoleInstanceEntity roleInstanceEntity, - Map map) { - + ClusterServiceRoleInstanceEntity roleInstanceEntity, + Map map) { + Map globalVariable = GlobalVariables.get(roleInstanceEntity.getClusterId()); String commandLine = getRMStateCommand(globalVariable, roleInstanceEntity.getHostname()); getRMState(roleInstanceEntity, commandLine); } - + private String getRMStateCommand(Map globalVariable, String hostName) { - + String commandLine = null; String yarnAclAdminUser = globalVariable.get("${yarn.admin.acl}"); String rm2 = globalVariable.get("${rm2}"); String curRm = rm2.equals(hostName) ? "rm2" : "rm1"; - + if (StringUtils.isNotEmpty(yarnAclAdminUser)) { commandLine = String.format("sudo -u %s %s/bin/yarn rmadmin -getServiceState %s", yarnAclAdminUser, globalVariable.get("${HADOOP_HOME}"), curRm); @@ -142,9 +146,9 @@ private String getRMStateCommand(Map globalVariable, String host } return commandLine; } - + private void getRMState( - ClusterServiceRoleInstanceEntity roleInstanceEntity, String commandLine) { + ClusterServiceRoleInstanceEntity roleInstanceEntity, String commandLine) { ClusterServiceRoleInstanceWebuisService webuisService = SpringTool.getApplicationContext() .getBean(ClusterServiceRoleInstanceWebuisService.class); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/RangerAdminHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/RangerAdminHandlerStrategy.java index 759c29ff..7e8719c4 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/RangerAdminHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/RangerAdminHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.api.strategy; -import com.alibaba.fastjson.JSONObject; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceConfigMap; import com.datasophon.api.service.ClusterInfoService; @@ -34,8 +33,6 @@ import com.datasophon.dao.entity.ClusterServiceInstanceEntity; import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -43,20 +40,26 @@ import java.util.Objects; import java.util.stream.Collectors; -public class RangerAdminHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(RangerAdminHandlerStrategy.class); +import com.alibaba.fastjson.JSONObject; +public class RangerAdminHandlerStrategy extends ServiceHandlerAbstract implements ServiceRoleStrategy { + + private static final Logger logger = LoggerFactory.getLogger(RangerAdminHandlerStrategy.class); + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() == 1) { String rangerAdminUrl = "http://" + hosts.get(0) + ":6080"; logger.info("rangerAdminUrl is {}", rangerAdminUrl); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${rangerAdminUrl}", rangerAdminUrl); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${rangerAdminUrl}", + rangerAdminUrl); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); @@ -67,22 +70,26 @@ public void handlerConfig(Integer clusterId, List list, String se for (ServiceConfig config : list) { if ("enableHDFSPlugin".equals(config.getName()) && ((Boolean) config.getValue()).booleanValue()) { logger.info("enableHdfsPlugin"); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${enableHDFSPlugin}", "true"); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${enableHDFSPlugin}", + "true"); enableRangerPlugin(clusterId, "HDFS", "NameNode"); } if ("enableHIVEPlugin".equals(config.getName()) && ((Boolean) config.getValue()).booleanValue()) { logger.info("enableHivePlugin"); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${enableHIVEPlugin}", "true"); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${enableHIVEPlugin}", + "true"); enableRangerPlugin(clusterId, "HIVE", "HiveServer2"); } if ("enableHBASEPlugin".equals(config.getName()) && ((Boolean) config.getValue()).booleanValue()) { logger.info("enableHbasePlugin"); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${enableHBASEPlugin}", "true"); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${enableHBASEPlugin}", + "true"); enableRangerPlugin(clusterId, "HBASE", "HbaseMaster"); } if (config.getName().contains("Plugin") && !(Boolean) config.getValue()) { String configName = config.getName(); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${" + configName + "}", "false"); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${" + configName + "}", + "false"); } if ("enableKerberos".equals(config.getName())) { enableKerberos = isEnableKerberos(clusterId, globalVariables, enableKerberos, config, "RANGER"); @@ -98,23 +105,23 @@ public void handlerConfig(Integer clusterId, List list, String se } list.addAll(kbConfigs); } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } - + private void enableRangerPlugin(Integer clusterId, String serviceName, String serviceRoleName) { ClusterServiceInstanceService serviceInstanceService = SpringTool.getApplicationContext().getBean(ClusterServiceInstanceService.class); @@ -132,15 +139,15 @@ private void enableRangerPlugin(Integer clusterId, String serviceName, String se // 查询角色组id List roleList = roleInstanceService.getServiceRoleInstanceListByClusterIdAndRoleName(clusterId, serviceRoleName); - + if (Objects.nonNull(roleList) && roleList.size() > 0) { Integer roleGroupId = roleList.get(0).getRoleGroupId(); - + ClusterServiceRoleGroupConfig config = roleGroupConfigService.getConfigByRoleGroupId(roleGroupId); List serviceConfigs = JSONObject.parseArray(config.getConfigJson(), ServiceConfig.class); Map map = serviceConfigs.stream() .collect(Collectors.toMap(ServiceConfig::getName, serviceConfig -> serviceConfig, (v1, v2) -> v1)); - + String key = clusterInfo.getClusterFrame() + Constants.UNDERLINE + serviceName + Constants.CONFIG; List configs = ServiceConfigMap.get(key); for (ServiceConfig parameter : configs) { @@ -148,7 +155,7 @@ private void enableRangerPlugin(Integer clusterId, String serviceName, String se if (map.containsKey(name)) { parameter = map.get(name); } - + if ("permission".equals(parameter.getConfigType())) { parameter.setHidden(false); parameter.setRequired(true); @@ -157,7 +164,7 @@ private void enableRangerPlugin(Integer clusterId, String serviceName, String se parameter.setHidden(false); parameter.setRequired(true); parameter.setValue(true); - + } if ("rangerAdminUrl".equals(parameter.getName())) { parameter.setHidden(false); diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceHandlerAbstract.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceHandlerAbstract.java index aaddb737..f16d1e39 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceHandlerAbstract.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceHandlerAbstract.java @@ -27,7 +27,7 @@ import java.util.Map; public abstract class ServiceHandlerAbstract { - + public void removeConfigWithKerberos(List list, Map map, List configs) { for (ServiceConfig serviceConfig : configs) { @@ -38,6 +38,7 @@ public void removeConfigWithKerberos(List list, Map list, Map map, List configs) { for (ServiceConfig serviceConfig : configs) { @@ -48,7 +49,7 @@ public void removeConfigWithHA(List list, Map list, Map map, List configs) { for (ServiceConfig serviceConfig : configs) { @@ -59,7 +60,7 @@ public void removeConfigWithRack(List list, Map globalVariables, Map map, List configs, ArrayList kbConfigs) { for (ServiceConfig serviceConfig : configs) { @@ -68,7 +69,7 @@ public void addConfigWithKerberos(Map globalVariables, Map globalVariables, Map map, List configs, ArrayList kbConfigs) { for (ServiceConfig serviceConfig : configs) { @@ -77,7 +78,7 @@ public void addConfigWithHA(Map globalVariables, Map globalVariables, Map map, List configs, List rackConfigs) { for (ServiceConfig serviceConfig : configs) { @@ -86,7 +87,7 @@ public void addConfigWithRack(Map globalVariables, Map globalVariables, Map map, List rackConfigs, ServiceConfig serviceConfig) { if (map.containsKey(serviceConfig.getName())) { @@ -109,31 +110,35 @@ private void addConfig(Map globalVariables, Map globalVariables, boolean enableKerberos, ServiceConfig config, String serviceName) { if ((Boolean) config.getValue()) { enableKerberos = true; - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${enable" + serviceName + "Kerberos}", + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, + "${enable" + serviceName + "Kerberos}", "true"); } else { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${enable" + serviceName + "Kerberos}", + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, + "${enable" + serviceName + "Kerberos}", "false"); } return enableKerberos; } - + public boolean isEnableHA(Integer clusterId, Map globalVariables, boolean enableHA, ServiceConfig config, String serviceName) { if ((Boolean) config.getValue()) { enableHA = true; - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${enable" + serviceName + "HA}", "true"); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, + "${enable" + serviceName + "HA}", "true"); } else { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${enable" + serviceName + "HA}", "false"); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, + "${enable" + serviceName + "HA}", "false"); } return enableHA; } - + public boolean isEnableRack(boolean enableRack, ServiceConfig config) { if ((Boolean) config.getValue()) { enableRack = true; diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategy.java index f626a07b..3a8e3883 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategy.java @@ -25,15 +25,15 @@ import java.util.Map; public interface ServiceRoleStrategy { - + void handler(Integer clusterId, List hosts, String serviceName); - + void handlerConfig(Integer clusterId, List list, String serviceName); - + void getConfig(Integer clusterId, List list); - + void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname); - + void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategyContext.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategyContext.java index ca109680..85c66331 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategyContext.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/ServiceRoleStrategyContext.java @@ -17,17 +17,17 @@ package com.datasophon.api.strategy; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class ServiceRoleStrategyContext { - + private static final Map strategyMap = new ConcurrentHashMap<>(); - + private static final Map serviceNameMap = new ConcurrentHashMap<>(); - + static { strategyMap.put("NameNode", new NameNodeHandlerStrategy()); strategyMap.put("ResourceManager", new RMHandlerStrategy()); @@ -52,7 +52,7 @@ public class ServiceRoleStrategyContext { strategyMap.put("ElasticSearch", new ElasticSearchHandlerStrategy()); strategyMap.put("Prometheus", new PrometheusHandlerStrategy()); strategyMap.put("AlertManager", new AlertManagerHandlerStrategy()); - + strategyMap.put("RANGER", new RangerAdminHandlerStrategy()); strategyMap.put("ZOOKEEPER", new ZkServerHandlerStrategy()); strategyMap.put("YARN", new RMHandlerStrategy()); @@ -62,8 +62,7 @@ public class ServiceRoleStrategyContext { strategyMap.put("HBASE", new HBaseHandlerStrategy()); strategyMap.put("FLINK", new FlinkHandlerStrategy()); strategyMap.put("KYUUBI", new KyuubiServerHandlerStrategy()); - - + // serviceNameMap serviceNameMap.put("NameNode", "HDFS"); serviceNameMap.put("ResourceManager", "YARN"); @@ -88,26 +87,25 @@ public class ServiceRoleStrategyContext { serviceNameMap.put("ElasticSearch", "ELASTICSEARCH"); serviceNameMap.put("Prometheus", "PROMETHEUS"); serviceNameMap.put("AlertManager", "ALERTMANAGER"); - - - serviceNameMap.put("FLINK","FLINK"); - serviceNameMap.put("RANGER","RANGER"); - serviceNameMap.put("YARN","YARN"); - serviceNameMap.put("HDFS","HDFS"); - serviceNameMap.put("HIVE","HIVE"); - serviceNameMap.put("KAFKA","KAFKA"); - serviceNameMap.put("HBASE","HBASE"); - serviceNameMap.put("KYUUBI","KYUUBI"); - + + serviceNameMap.put("FLINK", "FLINK"); + serviceNameMap.put("RANGER", "RANGER"); + serviceNameMap.put("YARN", "YARN"); + serviceNameMap.put("HDFS", "HDFS"); + serviceNameMap.put("HIVE", "HIVE"); + serviceNameMap.put("KAFKA", "KAFKA"); + serviceNameMap.put("HBASE", "HBASE"); + serviceNameMap.put("KYUUBI", "KYUUBI"); + } - + public static ServiceRoleStrategy getServiceRoleHandler(String type) { if (StringUtils.isBlank(type)) { return null; } return strategyMap.get(type); } - + public static String getServiceName(String type) { if (StringUtils.isBlank(type)) { return null; diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/TSHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/TSHandlerStrategy.java index 972f3ddb..d7f99076 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/TSHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/TSHandlerStrategy.java @@ -24,11 +24,12 @@ import com.datasophon.common.model.ServiceConfig; import com.datasophon.common.model.ServiceRoleInfo; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import lombok.extern.slf4j.Slf4j; import java.util.List; import java.util.Map; +import lombok.extern.slf4j.Slf4j; + /** * * Yarn Timeline Server @@ -38,28 +39,29 @@ */ @Slf4j public class TSHandlerStrategy implements ServiceRoleStrategy { - + @Override - public void handler(Integer clusterId, List hosts,String serviceName) { + public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); - if(hosts.size() > 0) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${yarn_timeline_server}", hosts.get(0)); + if (hosts.size() > 0) { + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${yarn_timeline_server}", + hosts.get(0)); } } - + @Override - public void handlerConfig(Integer clusterId, List list,String serviceName) { - + public void handlerConfig(Integer clusterId, List list, String serviceName) { + } - + @Override public void getConfig(Integer clusterId, List list) { } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { } - + @Override public void handlerServiceRoleCheck( ClusterServiceRoleInstanceEntity roleInstanceEntity, diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/TrinoHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/TrinoHandlerStrategy.java index 6bada0bb..5ed1c8b6 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/TrinoHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/TrinoHandlerStrategy.java @@ -27,33 +27,34 @@ import java.util.Map; public class TrinoHandlerStrategy implements ServiceRoleStrategy { - + @Override - public void handler(Integer clusterId, List hosts,String serviceName) { + public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); if (hosts.size() == 1) { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${coordinatorHost}", hosts.get(0)); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${coordinatorHost}", + hosts.get(0)); } } - + @Override - public void handlerConfig(Integer clusterId, List list,String serviceName) { - + public void handlerConfig(Integer clusterId, List list, String serviceName) { + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/ZKFCHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/ZKFCHandlerStrategy.java index 0c736dfc..8abde8f1 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/ZKFCHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/ZKFCHandlerStrategy.java @@ -22,16 +22,17 @@ import com.datasophon.common.model.ServiceConfig; import com.datasophon.common.model.ServiceRoleInfo; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; -public class ZKFCHandlerStrategy implements ServiceRoleStrategy { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +public class ZKFCHandlerStrategy implements ServiceRoleStrategy { + private static final Logger logger = LoggerFactory.getLogger(ZKFCHandlerStrategy.class); - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); @@ -40,17 +41,17 @@ public void handler(Integer clusterId, List hosts, String serviceName) { ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${ZKFC2}", hosts.get(1)); } } - + @Override public void handlerConfig(Integer clusterId, List list, String serviceName) { - + } - + @Override public void getConfig(Integer clusterId, List list) { - + } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { Map globalVariables = GlobalVariables.get(serviceRoleInfo.getClusterId()); @@ -60,10 +61,10 @@ public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostn serviceRoleInfo.setSortNum(6); } } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/strategy/ZkServerHandlerStrategy.java b/datasophon-service/src/main/java/com/datasophon/api/strategy/ZkServerHandlerStrategy.java index b44590e4..a0897467 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/strategy/ZkServerHandlerStrategy.java +++ b/datasophon-service/src/main/java/com/datasophon/api/strategy/ZkServerHandlerStrategy.java @@ -30,48 +30,55 @@ import com.datasophon.common.utils.PlaceholderUtils; import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; -import java.util.*; - public class ZkServerHandlerStrategy implements ServiceRoleStrategy { - + private static final Logger logger = LoggerFactory.getLogger(ZkServerHandlerStrategy.class); - + @Override public void handler(Integer clusterId, List hosts, String serviceName) { // 保存zkUrls到全局变量 Map globalVariables = GlobalVariables.get(clusterId); String join = String.join(":2181,", hosts); String zkUrls = join + ":2181"; - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${zkUrls}", zkUrls); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${zkUrls}", zkUrls); // 保存hbaseZkUrls到全局变量 - String hbaseZkUrls=String.join(",", hosts); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${zkHostsUrl}", hbaseZkUrls); + String hbaseZkUrls = String.join(",", hosts); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, "${zkHostsUrl}", hbaseZkUrls); } - + @Override - public void handlerConfig(Integer clusterId, List list,String serviceName) { + public void handlerConfig(Integer clusterId, List list, String serviceName) { Map globalVariables = GlobalVariables.get(clusterId); ClusterInfoEntity clusterInfo = ProcessUtils.getClusterInfo(clusterId); boolean enableKerberos = false; Map map = ProcessUtils.translateToMap(list); - + for (ServiceConfig config : list) { if ("enableKerberos".equals(config.getName())) { if ((Boolean) config.getValue()) { enableKerberos = true; - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${enableZOOKEEPERKerberos}", + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, + "${enableZOOKEEPERKerberos}", "true"); } else { - ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName,"${enableZOOKEEPERKerberos}", + ProcessUtils.generateClusterVariable(globalVariables, clusterId, serviceName, + "${enableZOOKEEPERKerberos}", "false"); } } } - + String key = clusterInfo.getClusterFrame() + Constants.UNDERLINE + "ZOOKEEPER" + Constants.CONFIG; List configs = ServiceConfigMap.get(key); ArrayList kbConfigs = new ArrayList<>(); @@ -107,6 +114,7 @@ public void handlerConfig(Integer clusterId, List list,String ser } list.addAll(kbConfigs); } + /** * * @param clusterId @@ -117,15 +125,15 @@ public void getConfig(Integer clusterId, List list) { // add server.x config ClusterInfoService clusterInfoService = SpringTool.getApplicationContext().getBean(ClusterInfoService.class); ClusterInfoEntity clusterInfo = clusterInfoService.getById(clusterId); - + String hostMapKey = clusterInfo.getClusterCode() + Constants.UNDERLINE + Constants.SERVICE_ROLE_HOST_MAPPING; HashMap> hostMap = (HashMap>) CacheUtils.get(hostMapKey); - + if (Objects.nonNull(hostMap)) { List zkServers = hostMap.get("ZkServer"); - + Map map = ProcessUtils.translateToMap(list); - + Integer myid = 1; for (String server : zkServers) { ServiceConfig serviceConfig = new ServiceConfig(); @@ -150,15 +158,15 @@ public void getConfig(Integer clusterId, List list) { } } } - + @Override public void handlerServiceRoleInfo(ServiceRoleInfo serviceRoleInfo, String hostname) { - + } - + @Override public void handlerServiceRoleCheck(ClusterServiceRoleInstanceEntity roleInstanceEntity, Map map) { - + } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/CheckUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/CheckUtils.java index 98fcad22..8bcae0a2 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/CheckUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/CheckUtils.java @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.api.utils; import com.datasophon.api.enums.Status; import com.datasophon.common.Constants; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.text.MessageFormat; import java.util.HashMap; @@ -27,10 +28,11 @@ import java.util.regex.Pattern; public class CheckUtils { - + private CheckUtils() { throw new IllegalStateException("CheckUtils class"); } + /** * check username * @@ -40,7 +42,7 @@ private CheckUtils() { public static boolean checkUserName(String userName) { return regexChecks(userName, Constants.REGEX_USER_NAME); } - + /** * check email * @@ -51,10 +53,10 @@ public static boolean checkEmail(String email) { if (StringUtils.isEmpty(email)) { return false; } - + return email.length() > 5 && email.length() <= 40 && regexChecks(email, Constants.REGEX_MAIL_NAME); } - + /** * check project description * @@ -72,7 +74,7 @@ public static Map checkDesc(String desc) { } return result; } - + /** * check password * @@ -82,23 +84,25 @@ public static Map checkDesc(String desc) { public static boolean checkPassword(String password) { return StringUtils.isNotEmpty(password) && password.length() >= 2 && password.length() <= 20; } - + /** * check phone * phone can be empty. + * * @param phone phone * @return true if phone regex valid, otherwise return false */ public static boolean checkPhone(String phone) { return StringUtils.isEmpty(phone) || phone.length() == 11; } - + /** * check params + * * @param userName user name * @param password password - * @param email email - * @param phone phone + * @param email email + * @param phone phone * @return true if user parameters are valid, other return false */ public static boolean checkUserParams(String userName, String password, String email, String phone) { @@ -107,11 +111,11 @@ public static boolean checkUserParams(String userName, String password, String e CheckUtils.checkPassword(password) && CheckUtils.checkPhone(phone); } - + /** * regex check * - * @param str input string + * @param str input string * @param pattern regex pattern * @return true if regex pattern is right, otherwise return false */ @@ -119,7 +123,7 @@ private static boolean regexChecks(String str, Pattern pattern) { if (StringUtils.isEmpty(str)) { return false; } - + return pattern.matcher(str).matches(); } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/CommonUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/CommonUtils.java index d8b42345..ccbb51d6 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/CommonUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/CommonUtils.java @@ -25,17 +25,17 @@ import org.slf4j.LoggerFactory; public class CommonUtils { - + private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class); - + private CommonUtils() { } - + public static void updateInstallState(InstallState installState, HostInfo hostInfo) { hostInfo.setInstallState(installState); hostInfo.setInstallStateCode(installState.getValue()); } - + public static RoleType convertRoleType(String roleType) { if (roleType == null || "".equals(roleType.trim())) { logger.error("Convert role type failed, roleType is null."); diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/ExecuteShellScriptUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/ExecuteShellScriptUtils.java index f8e78c9a..090cc5c4 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/ExecuteShellScriptUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/ExecuteShellScriptUtils.java @@ -1,25 +1,22 @@ package com.datasophon.api.utils; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import com.datasophon.api.master.DispatcherWorkerActor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ExecuteShellScriptUtils { + private static final Logger logger = LoggerFactory.getLogger(ExecuteShellScriptUtils.class); - public static int executeShellScript(String shellScriptPath,String params) throws IOException, InterruptedException { + public static int executeShellScript(String shellScriptPath, + String params) throws IOException, InterruptedException { logger.info("start executeShellScript:{}", shellScriptPath); - ProcessBuilder pb = new ProcessBuilder("sh",shellScriptPath,params); - //pb.inheritIO(); + ProcessBuilder pb = new ProcessBuilder("sh", shellScriptPath, params); + // pb.inheritIO(); Process p = pb.start(); - /*BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line; - while ((line = reader.readLine()) != null){ - System.out.println(line); - }*/ + /* + * BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = reader.readLine()) != null){ System.out.println(line); } + */ return p.waitFor(); } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/HadoopUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/HadoopUtils.java index 1dc7caac..95ca1b8a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/HadoopUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/HadoopUtils.java @@ -17,9 +17,6 @@ package com.datasophon.api.utils; -import akka.actor.ActorSelection; -import akka.pattern.Patterns; -import akka.util.Timeout; import com.datasophon.api.master.ActorUtils; import com.datasophon.api.master.handler.service.ServiceConfigureHandler; import com.datasophon.common.Constants; @@ -30,6 +27,7 @@ import com.datasophon.common.utils.ExecResult; import com.datasophon.dao.entity.ClusterInfoEntity; import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -39,8 +37,12 @@ import java.util.List; import java.util.concurrent.TimeUnit; -public class HadoopUtils { +import akka.actor.ActorSelection; +import akka.pattern.Patterns; +import akka.util.Timeout; +public class HadoopUtils { + public static ExecResult configQueueProp(ClusterInfoEntity clusterInfo, HashMap> configFileMap, ClusterServiceRoleInstanceEntity roleInstanceEntity) throws Exception { @@ -55,7 +57,7 @@ public static ExecResult configQueueProp(ClusterInfoEntity clusterInfo, ExecResult execResult = configureHandler.handlerRequest(serviceRoleInfo); return execResult; } - + public static ExecResult refreshQueuePropToYarn(ClusterInfoEntity clusterInfo, String hostname) throws Exception { ActorSelection execCmdActor = ActorUtils.actorSystem .actorSelection("akka.tcp://datasophon@" + hostname + ":2552/user/worker/executeCmdActor"); diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/HttpUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/HttpUtils.java index d0be460a..97ef21a9 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/HttpUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/HttpUtils.java @@ -19,15 +19,15 @@ import com.datasophon.common.Constants; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import javax.servlet.http.HttpServletRequest; public class HttpUtils { - + public static String getClientIpAddress(HttpServletRequest request) { String clientIp = request.getHeader(Constants.HTTP_X_FORWARDED_FOR); - + if (StringUtils.isNotEmpty(clientIp) && !clientIp.equalsIgnoreCase(Constants.HTTP_HEADER_UNKNOWN)) { int index = clientIp.indexOf(Constants.COMMA); if (index != -1) { @@ -36,12 +36,12 @@ public static String getClientIpAddress(HttpServletRequest request) { return clientIp; } } - + clientIp = request.getHeader(Constants.HTTP_X_REAL_IP); if (StringUtils.isNotEmpty(clientIp) && !clientIp.equalsIgnoreCase(Constants.HTTP_HEADER_UNKNOWN)) { return clientIp; } - + return request.getRemoteAddr(); } } diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/MessageResolverUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/MessageResolverUtils.java index 31bcc824..82716119 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/MessageResolverUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/MessageResolverUtils.java @@ -17,24 +17,25 @@ package com.datasophon.api.utils; -import cn.hutool.extra.spring.SpringUtil; +import java.util.Arrays; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; -import java.util.Arrays; +import cn.hutool.extra.spring.SpringUtil; /** * desc: 获取i18n资源文件 */ public class MessageResolverUtils { - + @Autowired private static MessageSource messageSource = SpringUtil.getBean(MessageSource.class); - + public MessageResolverUtils() { } - + /** * 根据 messageKey 获取国际化消息 委托给 spring messageSource * @@ -44,7 +45,7 @@ public MessageResolverUtils() { public static String getMessage(Object code) { return messageSource.getMessage(code.toString(), null, code.toString(), LocaleContextHolder.getLocale()); } - + /** * 根据 messageKey 和参数 获取消息 委托给 spring messageSource * diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/MinaUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/MinaUtils.java index 66642714..ce5491a4 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/MinaUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/MinaUtils.java @@ -46,9 +46,9 @@ import org.slf4j.LoggerFactory; public class MinaUtils { - + private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(MinaUtils.class); - + /** 打开远程会话 */ public static ClientSession openConnection(String sshHost, Integer sshPort, String sshUser) { SshClient sshClient = SshClient.setUpDefaultClient(); @@ -69,7 +69,7 @@ public static ClientSession openConnection(String sshHost, Integer sshPort, Stri LOG.info(sshHost + " 连接成功"); return session; } - + /** 关闭远程会话 */ public static void closeConnection(ClientSession session) { try { @@ -78,7 +78,7 @@ public static void closeConnection(ClientSession session) { throw new RuntimeException(e); } } - + /** 获取密钥对 */ static KeyPair getKeyPairFromString(String pk) { final KeyPairGenerator rsa; @@ -94,7 +94,7 @@ static KeyPair getKeyPairFromString(String pk) { throw new RuntimeException(e); } } - + /** * 同步执行,需要获取执行完的结果 * @@ -145,7 +145,7 @@ public static String execCmdWithResult(ClientSession session, String command) { LOG.info("exe cmd return : {}", out); return out.toString().trim(); } - + /** * 上传文件,相同路径ui覆盖 * @@ -177,7 +177,7 @@ public static boolean uploadFile(ClientSession session, String remotePath, Strin throw new RuntimeException(e); } } - + /** * 创建目录 * @@ -198,7 +198,7 @@ public static boolean createDir(ClientSession session, String path) { } return false; } - + public static void main(String[] args) throws IOException, InterruptedException { ClientSession session = MinaUtils.openConnection("localhost", 22, "liuxin"); for (int i = 0; i < Constants.TEN; i++) { diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/PackageUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/PackageUtils.java index b68ae2e6..43f882e1 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/PackageUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/PackageUtils.java @@ -22,13 +22,13 @@ import java.util.HashMap; public class PackageUtils { - + static HashMap map = new HashMap(); - + public static void putServicePackageName(String frameCode, String serviceName, String dcPackageName) { map.put(frameCode + Constants.UNDERLINE + serviceName, dcPackageName); } - + public static String getServiceDcPackageName(String frameCode, String serviceName) { return map.get(frameCode + Constants.UNDERLINE + serviceName); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/ProcessUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/ProcessUtils.java index ba9d4cb5..558b324a 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/ProcessUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/ProcessUtils.java @@ -17,19 +17,6 @@ package com.datasophon.api.utils; -import akka.actor.ActorRef; -import akka.actor.ActorSelection; -import akka.actor.Props; -import akka.dispatch.OnComplete; -import akka.pattern.Patterns; -import akka.util.Timeout; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.crypto.SecureUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.datasophon.api.load.GlobalVariables; import com.datasophon.api.load.ServiceConfigMap; import com.datasophon.api.master.ActorUtils; @@ -37,8 +24,23 @@ import com.datasophon.api.master.MasterServiceActor; import com.datasophon.api.master.ServiceCommandActor; import com.datasophon.api.master.ServiceExecuteResultActor; -import com.datasophon.api.master.handler.service.*; -import com.datasophon.api.service.*; +import com.datasophon.api.master.handler.service.ServiceConfigureAsyncHandler; +import com.datasophon.api.master.handler.service.ServiceConfigureHandler; +import com.datasophon.api.master.handler.service.ServiceHandler; +import com.datasophon.api.master.handler.service.ServiceInstallHandler; +import com.datasophon.api.master.handler.service.ServiceStartHandler; +import com.datasophon.api.master.handler.service.ServiceStopHandler; +import com.datasophon.api.service.ClusterAlertHistoryService; +import com.datasophon.api.service.ClusterInfoService; +import com.datasophon.api.service.ClusterServiceCommandHostCommandService; +import com.datasophon.api.service.ClusterServiceInstanceConfigService; +import com.datasophon.api.service.ClusterServiceInstanceRoleGroupService; +import com.datasophon.api.service.ClusterServiceInstanceService; +import com.datasophon.api.service.ClusterServiceRoleInstanceService; +import com.datasophon.api.service.ClusterServiceRoleInstanceWebuisService; +import com.datasophon.api.service.ClusterVariableService; +import com.datasophon.api.service.ClusterZkService; +import com.datasophon.api.service.FrameServiceService; import com.datasophon.api.service.host.ClusterHostService; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; @@ -48,18 +50,45 @@ import com.datasophon.common.enums.CommandType; import com.datasophon.common.enums.ServiceExecuteState; import com.datasophon.common.enums.ServiceRoleType; -import com.datasophon.common.model.*; +import com.datasophon.common.model.DAGGraph; +import com.datasophon.common.model.ExternalLink; +import com.datasophon.common.model.Generators; +import com.datasophon.common.model.ServiceConfig; +import com.datasophon.common.model.ServiceExecuteResultMessage; +import com.datasophon.common.model.ServiceNode; +import com.datasophon.common.model.ServiceRoleInfo; +import com.datasophon.common.model.StartWorkerMessage; +import com.datasophon.common.model.UpdateCommandHostMessage; import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.HostUtils; import com.datasophon.common.utils.PlaceholderUtils; import com.datasophon.common.utils.PropertyUtils; -import com.datasophon.dao.entity.*; -import com.datasophon.dao.enums.*; +import com.datasophon.dao.entity.ClusterAlertHistory; +import com.datasophon.dao.entity.ClusterHostDO; +import com.datasophon.dao.entity.ClusterInfoEntity; +import com.datasophon.dao.entity.ClusterServiceCommandEntity; +import com.datasophon.dao.entity.ClusterServiceCommandHostCommandEntity; +import com.datasophon.dao.entity.ClusterServiceCommandHostEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceConfigEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceEntity; +import com.datasophon.dao.entity.ClusterServiceInstanceRoleGroup; +import com.datasophon.dao.entity.ClusterServiceRoleGroupConfig; +import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity; +import com.datasophon.dao.entity.ClusterServiceRoleInstanceWebuis; +import com.datasophon.dao.entity.ClusterVariable; +import com.datasophon.dao.entity.ClusterZk; +import com.datasophon.dao.entity.FrameServiceEntity; +import com.datasophon.dao.enums.AlertLevel; +import com.datasophon.dao.enums.CommandState; +import com.datasophon.dao.enums.NeedRestart; +import com.datasophon.dao.enums.RoleType; +import com.datasophon.dao.enums.ServiceRoleState; +import com.datasophon.dao.enums.ServiceState; import com.datasophon.domain.host.enums.HostState; import com.datasophon.domain.host.enums.MANAGED; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -67,14 +96,41 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -public class ProcessUtils { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +import akka.actor.ActorRef; +import akka.actor.ActorSelection; +import akka.actor.Props; +import akka.dispatch.OnComplete; +import akka.pattern.Patterns; +import akka.util.Timeout; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.crypto.SecureUtil; +public class ProcessUtils { + + private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); + public static void saveServiceInstallInfo(ServiceRoleInfo serviceRoleInfo) { ClusterServiceInstanceService serviceInstanceService = SpringTool.getApplicationContext().getBean(ClusterServiceInstanceService.class); @@ -87,9 +143,9 @@ public static void saveServiceInstallInfo(ServiceRoleInfo serviceRoleInfo) { SpringTool.getApplicationContext().getBean(ClusterServiceRoleInstanceWebuisService.class); ClusterServiceInstanceRoleGroupService roleGroupService = SpringTool.getApplicationContext().getBean(ClusterServiceInstanceRoleGroupService.class); - + ClusterInfoEntity clusterInfo = clusterInfoService.getById(serviceRoleInfo.getClusterId()); - + ClusterServiceInstanceEntity clusterServiceInstance = serviceInstanceService.getServiceInstanceByClusterIdAndServiceName(serviceRoleInfo.getClusterId(), serviceRoleInfo.getParentName()); @@ -121,7 +177,7 @@ public static void saveServiceInstallInfo(ServiceRoleInfo serviceRoleInfo) { } Integer roleGroupId = (Integer) CacheUtils.get("UseRoleGroup_" + clusterServiceInstance.getId()); ClusterServiceInstanceRoleGroup roleGroup = roleGroupService.getById(roleGroupId); - + // save role instance ClusterServiceRoleInstanceEntity roleInstanceEntity = serviceRoleInstanceService .getOneServiceRole(serviceRoleInfo.getName(), serviceRoleInfo.getHostname(), clusterInfo.getId()); @@ -147,7 +203,7 @@ public static void saveServiceInstallInfo(ServiceRoleInfo serviceRoleInfo) { clusterZk.setZkServer(roleInstance.getHostname()); clusterZkService.save(clusterZk); } - + if (Objects.nonNull(serviceRoleInfo.getExternalLink())) { ExternalLink externalLink = serviceRoleInfo.getExternalLink(); ClusterServiceRoleInstanceWebuis webui = webuisService.getRoleInstanceWebUi(roleInstance.getId()); @@ -166,20 +222,20 @@ public static void saveServiceInstallInfo(ServiceRoleInfo serviceRoleInfo) { webuisService.save(webuis); globalVariables.remove("${host}"); } - + } } - + } - + public static void saveHostInstallInfo(StartWorkerMessage message, String clusterCode, ClusterHostService clusterHostService) { ClusterInfoService clusterInfoService = SpringTool.getApplicationContext().getBean(ClusterInfoService.class); ClusterHostDO clusterHostDO = new ClusterHostDO(); BeanUtil.copyProperties(message, clusterHostDO); - + ClusterInfoEntity cluster = clusterInfoService.getClusterByClusterCode(clusterCode); - + clusterHostDO.setClusterId(cluster.getId()); clusterHostDO.setCheckTime(new Date()); clusterHostDO.setRack("/default-rack"); @@ -190,7 +246,7 @@ public static void saveHostInstallInfo(StartWorkerMessage message, String cluste clusterHostDO.setManaged(MANAGED.YES); clusterHostService.save(clusterHostDO); } - + public static void updateCommandStateToFailed(List commandIds) { for (String commandId : commandIds) { logger.info("command id is {}", commandId); @@ -204,7 +260,7 @@ public static void updateCommandStateToFailed(List commandIds) { if (hostCommandEntity.getCommandState() == CommandState.RUNNING) { logger.info("{} host command set to cancel", hostCommandEntity.getCommandName()); CancelCommandMap.put(hostCommandEntity.getHostCommandId(), hostCommandEntity.getCommandName()); - + hostCommandEntity.setCommandState(CommandState.CANCEL); hostCommandEntity.setCommandProgress(100); service.updateByHostCommandId(hostCommandEntity); @@ -227,12 +283,12 @@ public static void updateCommandStateToFailed(List commandIds) { } } } - + public static void tellCommandActorResult(String serviceName, ExecuteServiceRoleCommand executeServiceRoleCommand, ServiceExecuteState state) { ActorRef serviceExecuteResultActor = ActorUtils.getLocalActor(ServiceExecuteResultActor.class, ActorUtils.getActorRefName(ServiceExecuteResultActor.class)); - + ServiceExecuteResultMessage serviceExecuteResultMessage = new ServiceExecuteResultMessage(); serviceExecuteResultMessage.setServiceExecuteState(state); serviceExecuteResultMessage.setDag(executeServiceRoleCommand.getDag()); @@ -246,15 +302,15 @@ public static void tellCommandActorResult(String serviceName, ExecuteServiceRole serviceExecuteResultMessage.setErrorTaskList(executeServiceRoleCommand.getErrorTaskList()); serviceExecuteResultMessage.setReadyToSubmitTaskList(executeServiceRoleCommand.getReadyToSubmitTaskList()); serviceExecuteResultMessage.setCompleteTaskList(executeServiceRoleCommand.getCompleteTaskList()); - + serviceExecuteResultActor.tell(serviceExecuteResultMessage, ActorRef.noSender()); } - + public static ClusterServiceCommandHostCommandEntity handleCommandResult(String hostCommandId, Boolean execResult, String execOut) { ClusterServiceCommandHostCommandService service = SpringTool.getApplicationContext().getBean(ClusterServiceCommandHostCommandService.class); - + ClusterServiceCommandHostCommandEntity hostCommand = service.getByHostCommandId(hostCommandId); hostCommand.setCommandProgress(100); if (execResult) { @@ -279,31 +335,31 @@ public static ClusterServiceCommandHostCommandEntity handleCommandResult(String } else { message.setServiceRoleType(ServiceRoleType.WORKER); } - + ActorRef commandActor = ActorUtils.getLocalActor(ServiceCommandActor.class, "commandActor"); ActorUtils.actorSystem.scheduler().scheduleOnce(FiniteDuration.apply( 1L, TimeUnit.SECONDS), commandActor, message, ActorUtils.actorSystem.dispatcher(), ActorRef.noSender()); - + return hostCommand; } - + public static void buildExecuteServiceRoleCommand( - Integer clusterId, - CommandType commandType, - String clusterCode, - DAGGraph dag, - Map activeTaskList, - Map errorTaskList, - Map readyToSubmitTaskList, - Map completeTaskList, - String node, - List masterRoles, - ServiceRoleInfo workerRole, - ActorRef serviceActor, - ServiceRoleType serviceRoleType) { + Integer clusterId, + CommandType commandType, + String clusterCode, + DAGGraph dag, + Map activeTaskList, + Map errorTaskList, + Map readyToSubmitTaskList, + Map completeTaskList, + String node, + List masterRoles, + ServiceRoleInfo workerRole, + ActorRef serviceActor, + ServiceRoleType serviceRoleType) { ExecuteServiceRoleCommand executeServiceRoleCommand = new ExecuteServiceRoleCommand(clusterId, node, masterRoles); executeServiceRoleCommand.setServiceRoleType(serviceRoleType); @@ -318,7 +374,7 @@ public static void buildExecuteServiceRoleCommand( executeServiceRoleCommand.setWorkerRole(workerRole); serviceActor.tell(executeServiceRoleCommand, ActorRef.noSender()); } - + public static ClusterServiceCommandEntity generateCommandEntity(Integer clusterId, CommandType commandType, String serviceName) { ClusterServiceCommandEntity commandEntity = new ClusterServiceCommandEntity(); @@ -335,7 +391,7 @@ public static ClusterServiceCommandEntity generateCommandEntity(Integer clusterI commandEntity.setServiceName(serviceName); return commandEntity; } - + public static ClusterServiceCommandHostEntity generateCommandHostEntity(String commandId, String hostname) { ClusterServiceCommandHostEntity commandHost = new ClusterServiceCommandHostEntity(); String commandHostId = IdUtil.simpleUUID(); @@ -345,10 +401,10 @@ public static ClusterServiceCommandHostEntity generateCommandHostEntity(String c commandHost.setCommandState(CommandState.RUNNING); commandHost.setCommandProgress(0); commandHost.setCreateTime(new Date()); - + return commandHost; } - + public static ClusterServiceCommandHostCommandEntity generateCommandHostCommandEntity(CommandType commandType, String commandId, String serviceRoleName, @@ -370,7 +426,7 @@ public static ClusterServiceCommandHostCommandEntity generateCommandHostCommandE hostCommand.setCreateTime(new Date()); return hostCommand; } - + public static void updateServiceRoleState(CommandType commandType, String serviceRoleName, String hostname, Integer clusterId, ServiceRoleState serviceRoleState) { ClusterServiceRoleInstanceService serviceRoleInstanceService = @@ -384,9 +440,9 @@ public static void updateServiceRoleState(CommandType commandType, String servic } serviceRoleInstanceService.updateById(serviceRole); } - + public static void generateClusterVariable(Map globalVariables, Integer clusterId, - String serviceName,String variableName, String value) { + String serviceName, String variableName, String value) { ClusterVariableService variableService = SpringTool.getApplicationContext().getBean(ClusterVariableService.class); ClusterVariable clusterVariable = variableService.getVariableByVariableName(variableName, clusterId); @@ -405,15 +461,15 @@ public static void generateClusterVariable(Map globalVariables, } globalVariables.put(variableName, value); } - + public static void hdfsEcMethond(Integer serviceInstanceId, ClusterServiceRoleInstanceService roleInstanceService, TreeSet list, String type, String roleName) throws Exception { - + List namenodes = roleInstanceService.lambdaQuery() .eq(ClusterServiceRoleInstanceEntity::getServiceId, serviceInstanceId) .eq(ClusterServiceRoleInstanceEntity::getServiceRoleName, roleName) .list(); - + // 更新namenode节点的whitelist白名单 for (ClusterServiceRoleInstanceEntity namenode : namenodes) { ActorSelection actorSelection = ActorUtils.actorSystem.actorSelection( @@ -443,10 +499,10 @@ public static void hdfsEcMethond(Integer serviceInstanceId, ClusterServiceRoleIn } } } - + public static void createServiceActor(ClusterInfoEntity clusterInfo) { FrameServiceService frameServiceService = SpringTool.getApplicationContext().getBean(FrameServiceService.class); - + List frameServiceList = frameServiceService.getAllFrameServiceByFrameCode(clusterInfo.getClusterFrame()); for (FrameServiceEntity frameServiceEntity : frameServiceList) { @@ -454,11 +510,11 @@ public static void createServiceActor(ClusterInfoEntity clusterInfo) { logger.info("create {} actor", clusterInfo.getClusterCode() + "-serviceActor-" + frameServiceEntity.getServiceName()); ActorUtils.actorSystem.actorOf(Props.create(MasterServiceActor.class) - .withDispatcher("my-forkjoin-dispatcher"), + .withDispatcher("my-forkjoin-dispatcher"), clusterInfo.getClusterCode() + "-serviceActor-" + frameServiceEntity.getServiceName()); } } - + public static String getExceptionMessage(Exception ex) { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream pout = new PrintStream(out); @@ -471,7 +527,7 @@ public static String getExceptionMessage(Exception ex) { } return ret; } - + public static ExecResult restartService(ServiceRoleInfo serviceRoleInfo, boolean needReConfig) throws Exception { ServiceHandler serviceStartHandler = new ServiceStartHandler(); ServiceHandler serviceStopHandler = new ServiceStopHandler(); @@ -484,7 +540,7 @@ public static ExecResult restartService(ServiceRoleInfo serviceRoleInfo, boolean } return serviceStopHandler.handlerRequest(serviceRoleInfo); } - + public static ExecResult startService(ServiceRoleInfo serviceRoleInfo, boolean needReConfig) throws Exception { ExecResult execResult; if (needReConfig) { @@ -498,7 +554,7 @@ public static ExecResult startService(ServiceRoleInfo serviceRoleInfo, boolean n } return execResult; } - + public static ExecResult startInstallService(ServiceRoleInfo serviceRoleInfo) throws Exception { ServiceHandler serviceInstallHandler = new ServiceInstallHandler(); ServiceHandler serviceConfigureHandler = new ServiceConfigureHandler(); @@ -508,7 +564,7 @@ public static ExecResult startInstallService(ServiceRoleInfo serviceRoleInfo) th ExecResult execResult = serviceInstallHandler.handlerRequest(serviceRoleInfo); return execResult; } - + public static ExecResult configServiceRoleInstance(ClusterInfoEntity clusterInfo, Map> configFileMap, ClusterServiceRoleInstanceEntity roleInstanceEntity) throws Exception { @@ -516,12 +572,13 @@ public static ExecResult configServiceRoleInstance(ClusterInfoEntity clusterInfo serviceRoleInfo.setName(roleInstanceEntity.getServiceRoleName()); serviceRoleInfo.setParentName(roleInstanceEntity.getServiceName()); serviceRoleInfo.setConfigFileMap(configFileMap); - serviceRoleInfo.setDecompressPackageName(PackageUtils.getServiceDcPackageName(clusterInfo.getClusterFrame(), "YARN")); + serviceRoleInfo + .setDecompressPackageName(PackageUtils.getServiceDcPackageName(clusterInfo.getClusterFrame(), "YARN")); serviceRoleInfo.setHostname(roleInstanceEntity.getHostname()); ServiceConfigureHandler configureHandler = new ServiceConfigureHandler(); return configureHandler.handlerRequest(serviceRoleInfo); } - + public static void asyncConfigServiceRoleInstance(ClusterInfoEntity clusterInfo, Map> configFileMap, ClusterServiceRoleInstanceEntity roleInstanceEntity, @@ -530,48 +587,49 @@ public static void asyncConfigServiceRoleInstance(ClusterInfoEntity clusterInfo, serviceRoleInfo.setName(roleInstanceEntity.getServiceRoleName()); serviceRoleInfo.setParentName(roleInstanceEntity.getServiceName()); serviceRoleInfo.setConfigFileMap(configFileMap); - serviceRoleInfo.setDecompressPackageName(PackageUtils.getServiceDcPackageName(clusterInfo.getClusterFrame(), "YARN")); + serviceRoleInfo + .setDecompressPackageName(PackageUtils.getServiceDcPackageName(clusterInfo.getClusterFrame(), "YARN")); serviceRoleInfo.setHostname(roleInstanceEntity.getHostname()); ServiceConfigureAsyncHandler configureAsyncHandler = new ServiceConfigureAsyncHandler(onComplete); configureAsyncHandler.handlerRequest(serviceRoleInfo); } - + /** * @param configFileMap * @param config * @Description: 生成configFileMap */ public static void generateConfigFileMap(Map> configFileMap, - ClusterServiceRoleGroupConfig config,Integer clusterId) { + ClusterServiceRoleGroupConfig config, Integer clusterId) { Map map = JSONObject.parseObject(config.getConfigFileJson(), Map.class); for (JSONObject fileJson : map.keySet()) { Generators generators = fileJson.toJavaObject(Generators.class); List serviceConfigs = map.get(fileJson).toJavaList(ServiceConfig.class); - //replace variable - replaceVariable(serviceConfigs,clusterId); + // replace variable + replaceVariable(serviceConfigs, clusterId); configFileMap.put(generators, serviceConfigs); } } - - private static void replaceVariable(List serviceConfigs,Integer clusterId) { + + private static void replaceVariable(List serviceConfigs, Integer clusterId) { Map globalVariables = GlobalVariables.get(clusterId); for (ServiceConfig serviceConfig : serviceConfigs) { - if(Constants.INPUT.equals(serviceConfig.getType())){ + if (Constants.INPUT.equals(serviceConfig.getType())) { String name = PlaceholderUtils.replacePlaceholders(serviceConfig.getName(), globalVariables, Constants.REGEX_VARIABLE); serviceConfig.setName(name); - + String value = PlaceholderUtils.replacePlaceholders((String) serviceConfig.getValue(), globalVariables, Constants.REGEX_VARIABLE); serviceConfig.setValue(value); } } } - + public static List getServiceConfig(ClusterServiceRoleGroupConfig config) { return JSONObject.parseArray(config.getConfigJson(), ServiceConfig.class); } - + public static ServiceConfig createServiceConfig(String configName, Object configValue, String type) { ServiceConfig serviceConfig = new ServiceConfig(); serviceConfig.setName(configName); @@ -582,12 +640,12 @@ public static ServiceConfig createServiceConfig(String configName, Object config serviceConfig.setType(type); return serviceConfig; } - + public static ClusterInfoEntity getClusterInfo(Integer clusterId) { ClusterInfoService clusterInfoService = SpringTool.getApplicationContext().getBean(ClusterInfoService.class); return clusterInfoService.getById(clusterId); } - + /** * 并集:左边集合与右边集合合并 * @@ -618,7 +676,7 @@ public static List addAll(List left, List hostList, String groupName, String operate) { for (ClusterHostDO hostEntity : hostList) { ActorRef execCmdActor = ActorUtils.getRemoteActor(hostEntity.getHostname(), "unixGroupActor"); @@ -630,12 +688,12 @@ public static void syncUserGroupToHosts(List hostList, String gro execCmdActor.tell(command, ActorRef.noSender()); } } - + public static Map translateToMap(List list) { return list.stream() .collect(Collectors.toMap(ServiceConfig::getName, serviceConfig -> serviceConfig, (v1, v2) -> v1)); } - + public static void syncUserToHosts(List hostList, String username, String mainGroup, String otherGroup, String operate) { for (ClusterHostDO hostEntity : hostList) { @@ -656,7 +714,7 @@ public static void syncUserToHosts(List hostList, String username execCmdActor.tell(command, ActorRef.noSender()); } } - + public static void recoverAlert(ClusterServiceRoleInstanceEntity roleInstanceEntity) { ClusterServiceRoleInstanceService roleInstanceService = SpringTool.getApplicationContext().getBean(ClusterServiceRoleInstanceService.class); @@ -677,7 +735,7 @@ public static void recoverAlert(ClusterServiceRoleInstanceEntity roleInstanceEnt roleInstanceService.updateById(roleInstanceEntity); } } - + public static void saveAlert(ClusterServiceRoleInstanceEntity roleInstanceEntity, String alertTargetName, AlertLevel alertLevel, String alertAdvice) { ClusterServiceRoleInstanceService roleInstanceService = @@ -691,7 +749,7 @@ public static void saveAlert(ClusterServiceRoleInstanceEntity roleInstanceEntity .eq(Constants.CLUSTER_ID, roleInstanceEntity.getClusterId()) .eq(Constants.HOSTNAME, roleInstanceEntity.getHostname()) .eq(Constants.IS_ENABLED, 1)); - + ClusterServiceInstanceEntity serviceInstanceEntity = serviceInstanceService.getById(roleInstanceEntity.getServiceId()); if (Objects.isNull(clusterAlertHistory)) { @@ -710,7 +768,7 @@ public static void saveAlert(ClusterServiceRoleInstanceEntity roleInstanceEntity .isEnabled(1) .serviceInstanceId(roleInstanceEntity.getServiceId()) .build(); - + alertHistoryService.save(clusterAlertHistory); } // update service role instance state @@ -722,7 +780,7 @@ public static void saveAlert(ClusterServiceRoleInstanceEntity roleInstanceEntity } serviceInstanceService.updateById(serviceInstanceEntity); roleInstanceService.updateById(roleInstanceEntity); - + } - + } diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/SecurityUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/SecurityUtils.java index aee61d7f..db4b5d4c 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/SecurityUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/SecurityUtils.java @@ -17,27 +17,30 @@ package com.datasophon.api.utils; -import cn.hutool.core.convert.Convert; import com.datasophon.common.Constants; import com.datasophon.dao.entity.UserInfoEntity; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -public class SecurityUtils { +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import cn.hutool.core.convert.Convert; + +public class SecurityUtils { + public static HttpServletRequest getRequest() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); return request; } - + public static HttpSession getSession() { HttpSession session = getRequest().getSession(); return session; } + /** * 获取用户 */ @@ -45,13 +48,14 @@ public static String getUsername() { String username = getAuthUser().getUsername(); return null == username ? null : ServletUtils.urlDecode(username); } + /** * 获取用户ID */ public static Long getUserId() { return Convert.toLong(ServletUtils.getRequest().getHeader(Constants.DETAILS_USER_ID)); } - + /** * 是否为管理员 * @@ -62,7 +66,7 @@ public static boolean isAdmin(UserInfoEntity userInfoEntity) { Integer userId = userInfoEntity.getId(); return userId != null && 1 == userId; } - + public static UserInfoEntity getAuthUser() { return (UserInfoEntity) getRequest().getAttribute(Constants.SESSION_USER); } diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/ServletUtils.java b/datasophon-service/src/main/java/com/datasophon/api/utils/ServletUtils.java index 4d2a956e..8f598a96 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/ServletUtils.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/ServletUtils.java @@ -38,35 +38,35 @@ import cn.hutool.core.convert.Convert; public class ServletUtils { - + /** * 获取String参数 */ public static String getParameter(String name) { return getRequest().getParameter(name); } - + /** * 获取String参数 */ public static String getParameter(String name, String defaultValue) { return Convert.toStr(getRequest().getParameter(name), defaultValue); } - + /** * 获取Integer参数 */ public static Integer getParameterToInt(String name) { return Convert.toInt(getRequest().getParameter(name)); } - + /** * 获取Integer参数 */ public static Integer getParameterToInt(String name, Integer defaultValue) { return Convert.toInt(getRequest().getParameter(name), defaultValue); } - + /** * 获取request */ @@ -77,7 +77,7 @@ public static HttpServletRequest getRequest() { return null; } } - + /** * 获取response */ @@ -88,14 +88,14 @@ public static HttpServletResponse getResponse() { return null; } } - + /** * 获取session */ public static HttpSession getSession() { return getRequest().getSession(); } - + public static ServletRequestAttributes getRequestAttributes() { try { RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); @@ -104,7 +104,7 @@ public static ServletRequestAttributes getRequestAttributes() { return null; } } - + public static Map getHeaders(HttpServletRequest request) { Map map = new LinkedHashMap<>(); Enumeration enumeration = request.getHeaderNames(); @@ -117,7 +117,7 @@ public static Map getHeaders(HttpServletRequest request) { } return map; } - + /** * 将字符串渲染到客户端 * @@ -136,7 +136,7 @@ public static String renderString(HttpServletResponse response, String string) { } return null; } - + /** * 内容编码 * @@ -150,7 +150,7 @@ public static String urlEncode(String str) { return ""; } } - + /** * 内容解码 * diff --git a/datasophon-service/src/main/java/com/datasophon/api/utils/SpringTool.java b/datasophon-service/src/main/java/com/datasophon/api/utils/SpringTool.java index d21720de..b2e40bbd 100644 --- a/datasophon-service/src/main/java/com/datasophon/api/utils/SpringTool.java +++ b/datasophon-service/src/main/java/com/datasophon/api/utils/SpringTool.java @@ -24,9 +24,9 @@ @Component public final class SpringTool implements ApplicationContextAware { - + private static ApplicationContext applicationContext = null; - + @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (SpringTool.applicationContext == null) { @@ -36,13 +36,13 @@ public void setApplicationContext(ApplicationContext applicationContext) throws + applicationContext + "========"); } } - + public static ApplicationContext getApplicationContext() { return applicationContext; } - + public static Object getBean(String name) { return getApplicationContext().getBean(name); } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/WorkerApplicationServer.java b/datasophon-worker/src/main/java/com/datasophon/worker/WorkerApplicationServer.java index dc537ee1..f8c06bff 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/WorkerApplicationServer.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/WorkerApplicationServer.java @@ -19,15 +19,6 @@ package com.datasophon.worker; -import akka.actor.ActorRef; -import akka.actor.ActorSelection; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.event.EventStream; -import akka.remote.AssociatedEvent; -import akka.remote.AssociationErrorEvent; -import akka.remote.DisassociatedEvent; -import com.alibaba.fastjson.JSONObject; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.lifecycle.ServerLifeCycleManager; @@ -39,10 +30,6 @@ import com.datasophon.worker.actor.WorkerActor; import com.datasophon.worker.utils.ActorUtils; import com.datasophon.worker.utils.UnixUtils; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.net.InetAddress; import java.net.UnknownHostException; @@ -50,45 +37,61 @@ import java.util.HashMap; import java.util.Map; -public class WorkerApplicationServer { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(WorkerApplicationServer.class); +import com.alibaba.fastjson.JSONObject; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; - private static final String USER_DIR = "user.dir"; +import akka.actor.ActorRef; +import akka.actor.ActorSelection; +import akka.actor.ActorSystem; +import akka.actor.Props; +import akka.event.EventStream; +import akka.remote.AssociatedEvent; +import akka.remote.AssociationErrorEvent; +import akka.remote.DisassociatedEvent; +public class WorkerApplicationServer { + + private static final Logger logger = LoggerFactory.getLogger(WorkerApplicationServer.class); + + private static final String USER_DIR = "user.dir"; + private static final String MASTER_HOST = "masterHost"; - + private static final String WORKER = "worker"; - + private static final String SH = "sh"; - + private static final String NODE = "node"; - + private static final String HADOOP = "hadoop"; - + public static void main(String[] args) throws UnknownHostException { String hostname = InetAddress.getLocalHost().getHostName(); String workDir = System.getProperty(USER_DIR); String masterHost = PropertyUtils.getString(MASTER_HOST); String cpuArchitecture = ShellUtils.getCpuArchitecture(); - + CacheUtils.put(Constants.HOSTNAME, hostname); // init actor ActorSystem system = initActor(hostname); ActorUtils.setActorSystem(system); - + subscribeRemoteEvent(system); - + startNodeExporter(workDir, cpuArchitecture); - + Map userMap = new HashMap(16); initUserMap(userMap); - + createDefaultUser(userMap); - + tellToMaster(hostname, workDir, masterHost, cpuArchitecture, system); logger.info("start worker"); - + /* * registry hooks, which are called before the process exits */ @@ -101,18 +104,18 @@ public static void main(String[] args) throws UnknownHostException { } })); } - + private static void initUserMap(Map userMap) { userMap.put("hdfs", HADOOP); userMap.put("yarn", HADOOP); userMap.put("hive", HADOOP); userMap.put("mapred", HADOOP); userMap.put("hbase", HADOOP); - userMap.put("kyuubi",HADOOP); + userMap.put("kyuubi", HADOOP); userMap.put("flink", HADOOP); userMap.put("elastic", "elastic"); } - + private static void createDefaultUser(Map userMap) { for (Map.Entry entry : userMap.entrySet()) { String user = entry.getKey(); @@ -123,7 +126,7 @@ private static void createDefaultUser(Map userMap) { UnixUtils.createUnixUser(user, group, null); } } - + private static ActorSystem initActor(String hostname) { Config config = ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname); ActorSystem system = @@ -131,7 +134,7 @@ private static ActorSystem initActor(String hostname) { system.actorOf(Props.create(WorkerActor.class), WORKER); return system; } - + private static void subscribeRemoteEvent(ActorSystem system) { ActorRef remoteEventActor = system.actorOf(Props.create(RemoteEventActor.class), "remoteEventActor"); @@ -140,21 +143,21 @@ private static void subscribeRemoteEvent(ActorSystem system) { eventStream.subscribe(remoteEventActor, AssociatedEvent.class); eventStream.subscribe(remoteEventActor, DisassociatedEvent.class); } - + private static void tellToMaster( - String hostname, - String workDir, - String masterHost, - String cpuArchitecture, - ActorSystem system) { + String hostname, + String workDir, + String masterHost, + String cpuArchitecture, + ActorSystem system) { ActorSelection workerStartActor = system.actorSelection( "akka.tcp://datasophon@" + masterHost + ":2551/user/workerStartActor"); ExecResult result = ShellUtils.exceShell(workDir + "/script/host-info-collect.sh"); - if(!result.getExecResult()){ - logger.error("host info collect error:{}",result.getExecErrOut()); - }else { - logger.info("host info collect success:{}",result.getExecOut()); + if (!result.getExecResult()) { + logger.error("host info collect error:{}", result.getExecErrOut()); + } else { + logger.info("host info collect success:{}", result.getExecOut()); } StartWorkerMessage startWorkerMessage = JSONObject.parseObject(result.getExecOut(), StartWorkerMessage.class); @@ -163,27 +166,27 @@ private static void tellToMaster( startWorkerMessage.setHostname(hostname); workerStartActor.tell(startWorkerMessage, ActorRef.noSender()); } - + public static void close(String cause) { stopNodeExporter(); logger.info("Worker server stopped"); } - + private static void stopNodeExporter() { String workDir = System.getProperty(USER_DIR); String cpuArchitecture = ShellUtils.getCpuArchitecture(); operateNodeExporter(workDir, cpuArchitecture, "stop"); } - + private static void startNodeExporter(String workDir, String cpuArchitecture) { operateNodeExporter(workDir, cpuArchitecture, "restart"); } - + private static void operateNodeExporter( - String workDir, String cpuArchitecture, String operate) { + String workDir, String cpuArchitecture, String operate) { ArrayList commands = new ArrayList<>(); commands.add(SH); - if (Constants.x86_64.equals(cpuArchitecture)) { + if (Constants.X86_64.equals(cpuArchitecture)) { commands.add(workDir + "/node/x86/control.sh"); } else { commands.add(workDir + "/node/arm/control.sh"); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/AlertConfigActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/AlertConfigActor.java index 6c935ae6..b214d05c 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/AlertConfigActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/AlertConfigActor.java @@ -29,7 +29,7 @@ import akka.actor.UntypedActor; public class AlertConfigActor extends UntypedActor { - + @Override public void onReceive(Object message) throws Throwable, Throwable { if (message instanceof GenerateAlertConfigCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/CheckServiceStatusActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/CheckServiceStatusActor.java index 446a1dd0..494a0695 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/CheckServiceStatusActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/CheckServiceStatusActor.java @@ -27,9 +27,9 @@ import akka.actor.UntypedActor; public class CheckServiceStatusActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(CheckServiceStatusActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof InstallServiceRoleCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/ConfigureServiceActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/ConfigureServiceActor.java index 72a914f6..041b20a3 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/ConfigureServiceActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/ConfigureServiceActor.java @@ -27,23 +27,24 @@ import akka.actor.UntypedActor; public class ConfigureServiceActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(ConfigureServiceActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof GenerateServiceConfigCommand) { - + GenerateServiceConfigCommand command = (GenerateServiceConfigCommand) msg; logger.info("start configure {}", command.getServiceName()); - ConfigureServiceHandler serviceHandler = new ConfigureServiceHandler(command.getServiceName(), command.getServiceRoleName()); + ConfigureServiceHandler serviceHandler = + new ConfigureServiceHandler(command.getServiceName(), command.getServiceRoleName()); ExecResult startResult = serviceHandler.configure(command.getCofigFileMap(), command.getDecompressPackageName(), command.getMyid(), command.getServiceRoleName(), command.getRunAs()); getSender().tell(startResult, getSelf()); - + logger.info("{} configure result {}", command.getServiceName(), startResult.getExecResult() ? "success" : "failed"); } else { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/ExecuteCmdActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/ExecuteCmdActor.java index 86c0d826..36240dab 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/ExecuteCmdActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/ExecuteCmdActor.java @@ -25,7 +25,7 @@ import akka.actor.UntypedActor; public class ExecuteCmdActor extends UntypedActor { - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ExecuteCmdCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/FileOperateActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/FileOperateActor.java index 06252dc0..fb062eb9 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/FileOperateActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/FileOperateActor.java @@ -29,7 +29,7 @@ import cn.hutool.core.io.FileUtil; public class FileOperateActor extends UntypedActor { - + @Override public void onReceive(Object msg) throws Throwable, Throwable { if (msg instanceof FileOperateCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/InstallServiceActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/InstallServiceActor.java index 2c87c4ff..7156ec10 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/InstallServiceActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/InstallServiceActor.java @@ -17,31 +17,35 @@ package com.datasophon.worker.actor; -import akka.actor.UntypedActor; import com.datasophon.common.Constants; import com.datasophon.common.command.InstallServiceRoleCommand; import com.datasophon.common.enums.ServiceRoleType; import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.ShellUtils; import com.datasophon.worker.handler.InstallServiceHandler; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.File; import java.util.ArrayList; -public class InstallServiceActor extends UntypedActor { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(InstallServiceActor.class); +import akka.actor.UntypedActor; +public class InstallServiceActor extends UntypedActor { + + private static final Logger logger = LoggerFactory.getLogger(InstallServiceActor.class); + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof InstallServiceRoleCommand) { InstallServiceRoleCommand command = (InstallServiceRoleCommand) msg; ExecResult installResult = new ExecResult(); - InstallServiceHandler serviceHandler = new InstallServiceHandler(command.getFrameCode(), command.getServiceName(), command.getServiceRoleName()); - + InstallServiceHandler serviceHandler = new InstallServiceHandler(command.getFrameCode(), + command.getServiceName(), command.getServiceRoleName()); + logger.info("Start install package {}", command.getPackageName()); if (command.getDecompressPackageName().contains("kerberos")) { ArrayList commands = new ArrayList<>(); @@ -66,14 +70,16 @@ public void onReceive(Object msg) throws Throwable { installResult = serviceHandler.install(command); // 其他服务创建软连接 String appHome = Constants.INSTALL_PATH + Constants.SLASH + command.getDecompressPackageName(); - String appLinkHome = Constants.INSTALL_PATH + Constants.SLASH + StringUtils.lowerCase(command.getServiceName()); + String appLinkHome = + Constants.INSTALL_PATH + Constants.SLASH + StringUtils.lowerCase(command.getServiceName()); if (!new File(appLinkHome).exists()) { ShellUtils.exceShell("ln -s " + appHome + " " + appLinkHome); logger.info("Create symbolic dir: {}", appLinkHome); } } getSender().tell(installResult, getSelf()); - logger.info("Install {} {}", command.getPackageName(), installResult.getExecResult() ? "success" : "failed"); + logger.info("Install {} {}", command.getPackageName(), + installResult.getExecResult() ? "success" : "failed"); } else { unhandled(msg); } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/KerberosActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/KerberosActor.java index 3d4765de..839e02be 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/KerberosActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/KerberosActor.java @@ -29,9 +29,9 @@ import cn.hutool.core.io.FileUtil; public class KerberosActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(KerberosActor.class); - + @Override public void onReceive(Object message) throws Throwable { if (message instanceof GenerateKeytabFileCommand) { @@ -48,7 +48,7 @@ public void onReceive(Object message) throws Throwable { ShellUtils.exceShell(addprinc); String keytabCmd = "kadmin -padmin/admin -wadmin -q \"xst -k " + keytabFilePath + " " + command.getPrincipal() + "\""; - + logger.info("generate keytab file cmd :{}", keytabCmd); ShellUtils.exceShell(keytabCmd); } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/LogActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/LogActor.java index 9c35ac01..6c2dfff5 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/LogActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/LogActor.java @@ -17,26 +17,29 @@ package com.datasophon.worker.actor; -import akka.actor.UntypedActor; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.StrUtil; import com.datasophon.common.Constants; import com.datasophon.common.command.GetLogCommand; import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.PlaceholderUtils; import com.datasophon.common.utils.PropertyUtils; import com.datasophon.worker.utils.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.net.InetAddress; import java.nio.charset.Charset; import java.util.HashMap; -public class LogActor extends UntypedActor { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(LogActor.class); +import akka.actor.UntypedActor; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; +public class LogActor extends UntypedActor { + + private static final Logger logger = LoggerFactory.getLogger(LogActor.class); + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof GetLogCommand) { @@ -48,7 +51,7 @@ public void onReceive(Object msg) throws Throwable { paramMap.put("${host}", hostName); String logFileName = PlaceholderUtils.replacePlaceholders(command.getLogFile(), paramMap, Constants.REGEX_VARIABLE); - + ExecResult execResult = new ExecResult(); String logStr = "can not find log file"; if (logFileName.startsWith(StrUtil.SLASH) && FileUtil.exist(logFileName)) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/NMStateActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/NMStateActor.java index 45918cf7..9500abaf 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/NMStateActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/NMStateActor.java @@ -7,7 +7,7 @@ import akka.actor.UntypedActor; public class NMStateActor extends UntypedActor { - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ExecuteCmdCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/PingActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/PingActor.java index 480b0252..124e4016 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/PingActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/PingActor.java @@ -17,21 +17,23 @@ package com.datasophon.worker.actor; -import akka.actor.UntypedActor; import com.datasophon.common.command.PingCommand; import com.datasophon.common.utils.ExecResult; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import akka.actor.UntypedActor; + /** * 发送 ping,返回 pong * * @author zhenqin */ public class PingActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(PingActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof PingCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/RMStateActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/RMStateActor.java index 792ee443..0b4c6db6 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/RMStateActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/RMStateActor.java @@ -7,7 +7,7 @@ import akka.actor.UntypedActor; public class RMStateActor extends UntypedActor { - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ExecuteCmdCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/RemoteEventActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/RemoteEventActor.java index dfacea15..46f7b2c7 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/RemoteEventActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/RemoteEventActor.java @@ -26,9 +26,9 @@ import akka.remote.DisassociatedEvent; public class RemoteEventActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(RemoteEventActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof AssociationErrorEvent) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/RestartServiceActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/RestartServiceActor.java index e013a779..aead9f00 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/RestartServiceActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/RestartServiceActor.java @@ -24,7 +24,7 @@ import akka.actor.UntypedActor; public class RestartServiceActor extends UntypedActor { - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ServiceRoleOperateCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/StartServiceActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/StartServiceActor.java index 4e49dee1..d5590c16 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/StartServiceActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/StartServiceActor.java @@ -31,9 +31,9 @@ import akka.actor.UntypedActor; public class StartServiceActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(StartServiceActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ServiceRoleOperateCommand) { @@ -41,7 +41,7 @@ public void onReceive(Object msg) throws Throwable { logger.info("start to start service role {}", command.getServiceRoleName()); ExecResult startResult = new ExecResult(); ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); - + ServiceRoleStrategy serviceRoleHandler = ServiceRoleStrategyContext.getServiceRoleHandler(command.getServiceRoleName()); if (Objects.nonNull(serviceRoleHandler)) { @@ -50,13 +50,13 @@ public void onReceive(Object msg) throws Throwable { startResult = serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); } - + getSender().tell(startResult, getSelf()); logger.info("service role {} start result {}", command.getServiceRoleName(), startResult.getExecResult() ? "success" : "failed"); } else { unhandled(msg); } - + } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/StopServiceActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/StopServiceActor.java index 9a5827bd..fc23516a 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/StopServiceActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/StopServiceActor.java @@ -27,20 +27,20 @@ import akka.actor.UntypedActor; public class StopServiceActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(StopServiceActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof ServiceRoleOperateCommand) { ServiceRoleOperateCommand command = (ServiceRoleOperateCommand) msg; - + logger.info("start to stop service role {}", command.getServiceRoleName()); ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); ExecResult stopResult = serviceHandler.stop(command.getStopRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); getSender().tell(stopResult, getSelf()); - + logger.info("service role {} stop result {}", command.getServiceRoleName(), stopResult.getExecResult() ? "success" : "failed"); } else { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/SupervisorFunction.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/SupervisorFunction.java index 405fbe5f..2a65cc0c 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/SupervisorFunction.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/SupervisorFunction.java @@ -23,7 +23,7 @@ import akka.japi.Function; public class SupervisorFunction implements Function { - + @Override public SupervisorStrategy.Directive apply(Throwable param) throws Exception { if (param instanceof ArithmeticException) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixGroupActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixGroupActor.java index 9e48ea16..ca71bde2 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixGroupActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixGroupActor.java @@ -28,9 +28,9 @@ import akka.actor.UntypedActor; public class UnixGroupActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(UnixGroupActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof CreateUnixGroupCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixUserActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixUserActor.java index af46ef1e..5659fdb3 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixUserActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/UnixUserActor.java @@ -28,9 +28,9 @@ import akka.actor.UntypedActor; public class UnixUserActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(UnixUserActor.class); - + @Override public void onReceive(Object msg) throws Throwable { if (msg instanceof CreateUnixUserCommand) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/actor/WorkerActor.java b/datasophon-worker/src/main/java/com/datasophon/worker/actor/WorkerActor.java index 201555fb..5a5eb56e 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/actor/WorkerActor.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/actor/WorkerActor.java @@ -17,28 +17,29 @@ package com.datasophon.worker.actor; +import org.apache.commons.lang3.StringUtils; + +import scala.Option; + +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import akka.actor.ActorRef; import akka.actor.Props; import akka.actor.Terminated; import akka.actor.UntypedActor; -import com.alibaba.fastjson.JSONObject; -import com.datasophon.common.model.StartWorkerMessage; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import scala.Option; - -import java.io.IOException; public class WorkerActor extends UntypedActor { - + private static final Logger logger = LoggerFactory.getLogger(WorkerActor.class); - + @Override public void preRestart(Throwable reason, Option message) { logger.info("worker actor restart by reason {}", reason.getMessage()); } - + @Override public void preStart() throws IOException { ActorRef installServiceActor = getContext().actorOf(Props.create(InstallServiceActor.class), @@ -69,7 +70,7 @@ public void preStart() throws IOException { ActorRef rMStateActor = getContext().actorOf(Props.create(RMStateActor.class), getActorRefName(RMStateActor.class)); ActorRef pingActor = getContext().actorOf(Props.create(PingActor.class), getActorRefName(PingActor.class)); - + // 添加监听服务 getContext().watch(installServiceActor); getContext().watch(configureServiceActor); @@ -85,18 +86,18 @@ public void preStart() throws IOException { getContext().watch(kerberosActor); getContext().watch(rMStateActor); getContext().watch(nMStateActor); - getContext().watch(pingActor); + getContext().watch(pingActor); } - + /** Get ActorRef name from Class name. */ private String getActorRefName(Class clazz) { return StringUtils.uncapitalize(clazz.getSimpleName()); } - + @Override public void onReceive(Object message) throws Throwable { if (message instanceof String) { - + } else if (message instanceof Terminated) { Terminated t = (Terminated) message; logger.info("find actor {} terminated", t.getActor()); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/handler/ConfigureServiceHandler.java b/datasophon-worker/src/main/java/com/datasophon/worker/handler/ConfigureServiceHandler.java index 9dd588eb..2f441b23 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/handler/ConfigureServiceHandler.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/handler/ConfigureServiceHandler.java @@ -17,10 +17,6 @@ package com.datasophon.worker.handler; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.IdUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.datasophon.common.Constants; import com.datasophon.common.model.Generators; import com.datasophon.common.model.RunAs; @@ -30,10 +26,8 @@ import com.datasophon.common.utils.ShellUtils; import com.datasophon.worker.utils.FreemakerUtils; import com.datasophon.worker.utils.TaskConstants; -import lombok.Data; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.File; import java.net.InetAddress; @@ -45,27 +39,37 @@ import java.util.Objects; import java.util.Set; -@Data -public class ConfigureServiceHandler { +import lombok.Data; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final String RANGER_ADMIN = "RangerAdmin"; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; - private static final String SH = "sh"; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.IdUtil; +@Data +public class ConfigureServiceHandler { + + private static final String RANGER_ADMIN = "RangerAdmin"; + + private static final String SH = "sh"; + private String serviceName; - + private String serviceRoleName; - + private Logger logger; - + public ConfigureServiceHandler(String serviceName, String serviceRoleName) { this.serviceName = serviceName; this.serviceRoleName = serviceRoleName; String loggerName = String.format("%s-%s-%s", TaskConstants.TASK_LOG_LOGGER_NAME, serviceName, serviceRoleName); logger = LoggerFactory.getLogger(loggerName); } - + public ExecResult configure(Map> cofigFileMap, String decompressPackageName, Integer myid, @@ -73,7 +77,7 @@ public ExecResult configure(Map> cofigFileMap, RunAs runAs) { ExecResult execResult = new ExecResult(); try { - + String hostName = InetAddress.getLocalHost().getHostName(); HashMap paramMap = new HashMap<>(); paramMap.put("${host}", hostName); @@ -117,7 +121,7 @@ public ExecResult configure(Map> cofigFileMap, logger.info("Convert boolean and integer to string"); config.setValue(config.getValue().toString()); } - + if ("dataDir".equals(config.getName())) { logger.info("Find dataDir : {}", config.getValue()); dataDir = (String) config.getValue(); @@ -134,24 +138,26 @@ public ExecResult configure(Map> cofigFileMap, || "be_priority_networks".equals(config.getName())) { config.setName("priority_networks"); } - - if("KyuubiServer".equals(serviceRoleName) && "sparkHome".equals(config.getName())){ + + if ("KyuubiServer".equals(serviceRoleName) && "sparkHome".equals(config.getName())) { // add hive-site.xml link in kerberos module - final String targetPath = Constants.INSTALL_PATH + File.separator + decompressPackageName+"/conf/hive-site.xml"; - if(!FileUtil.exist(targetPath)){ + final String targetPath = + Constants.INSTALL_PATH + File.separator + decompressPackageName + "/conf/hive-site.xml"; + if (!FileUtil.exist(targetPath)) { logger.info("Add hive-site.xml link"); - ExecResult result = ShellUtils.exceShell("ln -s "+config.getValue()+"/conf/hive-site.xml "+targetPath); - if(!result.getExecResult()){ - logger.warn("Add hive-site.xml link failed,msg: "+result.getExecErrOut()); + ExecResult result = ShellUtils + .exceShell("ln -s " + config.getValue() + "/conf/hive-site.xml " + targetPath); + if (!result.getExecResult()) { + logger.warn("Add hive-site.xml link failed,msg: " + result.getExecErrOut()); } } } } - + if (Objects.nonNull(myid) && StringUtils.isNotBlank(dataDir)) { FileUtil.writeUtf8String(myid + "", dataDir + Constants.SLASH + "myid"); } - + if ("node.properties".equals(generators.getFilename())) { ServiceConfig serviceConfig = new ServiceConfig(); serviceConfig.setName("node.id"); @@ -172,7 +178,8 @@ public ExecResult configure(Map> cofigFileMap, FreemakerUtils.generateConfigFile(generators, configs, decompressPackageName); } } else if (!generators.getFilename().endsWith(SH)) { - String packagePath = Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + Constants.SLASH; + String packagePath = + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + Constants.SLASH; String outputFile = packagePath + generators.getOutputDirectory() + Constants.SLASH + generators.getFilename(); FileUtil.writeUtf8String("", outputFile); @@ -190,14 +197,14 @@ public ExecResult configure(Map> cofigFileMap, } return execResult; } - + private boolean setupRangerAdmin(String decompressPackageName) { logger.info("start to execute ranger admin setup.sh"); ArrayList commands = new ArrayList<>(); commands.add(Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + Constants.SLASH + "setup.sh"); ExecResult execResult = ShellUtils .execWithStatus(Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName, commands, 300L); - + ArrayList globalCommand = new ArrayList<>(); globalCommand.add( Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + Constants.SLASH + "set_globals.sh"); @@ -210,7 +217,7 @@ private boolean setupRangerAdmin(String decompressPackageName) { logger.info("ranger admin setup failed"); return false; } - + private void createPath(ServiceConfig config, RunAs runAs) { String path = (String) config.getValue(); if (StringUtils.isNotBlank(config.getSeparator()) && path.contains(config.getSeparator())) { @@ -221,7 +228,7 @@ private void createPath(ServiceConfig config, RunAs runAs) { mkdir(path, runAs); } } - + private void movePath(ServiceConfig config, RunAs runAs) { String oldPath = (String) config.getDefaultValue(); String newPath = (String) config.getValue(); @@ -237,7 +244,7 @@ private void movePath(ServiceConfig config, RunAs runAs) { logger.info("move path {} to {}", oldPath, newPath); } } - + private void addToCustomList(Iterator iterator, ArrayList customConfList, ServiceConfig config) { List list = (List) config.getValue(); @@ -256,7 +263,7 @@ private void addToCustomList(Iterator iterator, ArrayList strs = value.toJavaList(String.class); @@ -266,7 +273,7 @@ private String conventToStr(ServiceConfig config) { logger.info("config set value to {}", config.getValue()); return joinValue; } - + private void mkdir(String path, RunAs runAs) { if (!FileUtil.exist(path)) { logger.info("create file path {}", path); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/handler/InstallServiceHandler.java b/datasophon-worker/src/main/java/com/datasophon/worker/handler/InstallServiceHandler.java index b798dbdc..fb25fb7c 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/handler/InstallServiceHandler.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/handler/InstallServiceHandler.java @@ -17,57 +17,66 @@ package com.datasophon.worker.handler; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.bean.copier.CopyOptions; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.StreamProgress; -import cn.hutool.core.lang.Console; -import cn.hutool.http.HttpUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.InstallServiceRoleCommand; -import com.datasophon.common.model.RunAs; import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.FileUtils; import com.datasophon.common.utils.PropertyUtils; import com.datasophon.common.utils.ShellUtils; -import com.datasophon.worker.strategy.resource.*; +import com.datasophon.worker.strategy.resource.AppendLineStrategy; +import com.datasophon.worker.strategy.resource.DownloadStrategy; +import com.datasophon.worker.strategy.resource.EmptyStrategy; +import com.datasophon.worker.strategy.resource.LinkStrategy; +import com.datasophon.worker.strategy.resource.ReplaceStrategy; +import com.datasophon.worker.strategy.resource.ResourceStrategy; +import com.datasophon.worker.strategy.resource.ShellStrategy; import com.datasophon.worker.utils.TaskConstants; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.File; import java.util.ArrayList; import java.util.Map; import java.util.Objects; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.StreamProgress; +import cn.hutool.core.lang.Console; +import cn.hutool.http.HttpUtil; + @Slf4j @Data public class InstallServiceHandler { - - + private static final String HADOOP = "hadoop"; - + private String frameCode; - + private String serviceName; - + private String serviceRoleName; - + private Logger logger; - + public InstallServiceHandler(String frameCode, String serviceName, String serviceRoleName) { this.frameCode = frameCode; this.serviceName = serviceName; this.serviceRoleName = serviceRoleName; - String loggerName = String.format("%s-%s-%s-%s", TaskConstants.TASK_LOG_LOGGER_NAME, frameCode, serviceName, serviceRoleName); + String loggerName = String.format("%s-%s-%s-%s", TaskConstants.TASK_LOG_LOGGER_NAME, frameCode, serviceName, + serviceRoleName); logger = LoggerFactory.getLogger(loggerName); } - + public ExecResult install(InstallServiceRoleCommand command) { ExecResult execResult = new ExecResult(); try { @@ -75,14 +84,15 @@ public ExecResult install(InstallServiceRoleCommand command) { String packageName = command.getPackageName(); String packagePath = destDir + packageName; String decompressPackageName = command.getDecompressPackageName(); - - Boolean needDownLoad = !Objects.equals(PropertyUtils.getString(Constants.MASTER_HOST), CacheUtils.get(Constants.HOSTNAME)) - && isNeedDownloadPkg(packagePath, command.getPackageMd5()); - + + Boolean needDownLoad = + !Objects.equals(PropertyUtils.getString(Constants.MASTER_HOST), CacheUtils.get(Constants.HOSTNAME)) + && isNeedDownloadPkg(packagePath, command.getPackageMd5()); + if (Boolean.TRUE.equals(needDownLoad)) { downloadPkg(packageName, packagePath); } - + boolean result = decompressPkg(packageName, decompressPackageName, destDir); if (result) { if (CollUtil.isNotEmpty(command.getResourceStrategies())) { @@ -91,19 +101,24 @@ public ExecResult install(InstallServiceRoleCommand command) { ResourceStrategy rs; switch (type) { case ReplaceStrategy.REPLACE_TYPE: - rs = BeanUtil.mapToBean(strategy, ReplaceStrategy.class, true, CopyOptions.create().ignoreError()); + rs = BeanUtil.mapToBean(strategy, ReplaceStrategy.class, true, + CopyOptions.create().ignoreError()); break; case DownloadStrategy.DOWNLOAD_TYPE: - rs = BeanUtil.mapToBean(strategy, DownloadStrategy.class, true, CopyOptions.create().ignoreError()); + rs = BeanUtil.mapToBean(strategy, DownloadStrategy.class, true, + CopyOptions.create().ignoreError()); break; case AppendLineStrategy.APPEND_LINE_TYPE: - rs = BeanUtil.mapToBean(strategy, AppendLineStrategy.class, true, CopyOptions.create().ignoreError()); + rs = BeanUtil.mapToBean(strategy, AppendLineStrategy.class, true, + CopyOptions.create().ignoreError()); break; case LinkStrategy.LINK_TYPE: - rs = BeanUtil.mapToBean(strategy, LinkStrategy.class, true, CopyOptions.create().ignoreError()); + rs = BeanUtil.mapToBean(strategy, LinkStrategy.class, true, + CopyOptions.create().ignoreError()); break; case ShellStrategy.SHELL_TYPE: - rs = BeanUtil.mapToBean(strategy, ShellStrategy.class, true, CopyOptions.create().ignoreError()); + rs = BeanUtil.mapToBean(strategy, ShellStrategy.class, true, + CopyOptions.create().ignoreError()); break; default: rs = new EmptyStrategy(); @@ -115,13 +130,15 @@ public ExecResult install(InstallServiceRoleCommand command) { rs.exec(); } } - + if (Objects.nonNull(command.getRunAs())) { - ExecResult chownResult = ShellUtils.exceShell(" chown -R " + command.getRunAs().getUser() + ":" + command.getRunAs().getGroup() + " " - + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName); + ExecResult chownResult = ShellUtils.exceShell( + " chown -R " + command.getRunAs().getUser() + ":" + command.getRunAs().getGroup() + " " + + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName); logger.info("chown {} {}", decompressPackageName, chownResult.getExecResult() ? "success" : "fail"); } - ExecResult chmodResult = ShellUtils.exceShell(" chmod -R 775 " + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName); + ExecResult chmodResult = ShellUtils + .exceShell(" chmod -R 775 " + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName); logger.info("chmod {} {}", decompressPackageName, chmodResult.getExecResult() ? "success" : "fail"); if (decompressPackageName.contains(Constants.PROMETHEUS)) { String alertPath = Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName @@ -140,43 +157,44 @@ public ExecResult install(InstallServiceRoleCommand command) { } return execResult; } - + private Boolean isNeedDownloadPkg(String packagePath, String packageMd5) { boolean needDownLoad = true; logger.info("Remote package md5 is {}", packageMd5); if (FileUtil.exist(packagePath)) { // check md5 String md5 = FileUtils.md5(new File(packagePath)); - + logger.info("Local md5 is {}", md5); - + if (StringUtils.isNotBlank(md5) && packageMd5.trim().equals(md5.trim())) { needDownLoad = false; } } return needDownLoad; } - + private void downloadPkg(String packageName, String packagePath) { String masterHost = PropertyUtils.getString(Constants.MASTER_HOST); String masterPort = PropertyUtils.getString(Constants.MASTER_WEB_PORT); String downloadUrl = "http://" + masterHost + ":" + masterPort + "/ddh/service/install/downloadPackage?packageName=" + packageName; - + logger.info("download url is {}", downloadUrl); - + HttpUtil.downloadFile(downloadUrl, FileUtil.file(packagePath), new StreamProgress() { - + @Override public void start() { Console.log("start to install。。。。"); } - + @Override public void progress(long progressSize, long l1) { - Console.log("installed:{} / {} ", FileUtil.readableFileSize(progressSize), FileUtil.readableFileSize(l1)); + Console.log("installed:{} / {} ", FileUtil.readableFileSize(progressSize), + FileUtil.readableFileSize(l1)); } - + @Override public void finish() { Console.log("install success!"); @@ -184,7 +202,7 @@ public void finish() { }); logger.info("download package {} success", packageName); } - + private boolean decompressPkg(String packageName, String decompressPackageName, String destDir) { boolean decompressResult = true; if (!FileUtil.exist(Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName)) { @@ -192,7 +210,7 @@ private boolean decompressPkg(String packageName, String decompressPackageName, } return decompressResult; } - + public boolean decompressTarGz(String sourceTarGzFile, String targetDir) { logger.info("Start to use tar -zxvf to decompress {}", sourceTarGzFile); ArrayList command = new ArrayList<>(); @@ -204,8 +222,7 @@ public boolean decompressTarGz(String sourceTarGzFile, String targetDir) { ExecResult execResult = ShellUtils.execWithStatus(targetDir, command, 120, logger); return execResult.getExecResult(); } - - + private void changeHadoopInstallPathPerm(String decompressPackageName) { ShellUtils.exceShell( " chown -R root:hadoop " + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName); @@ -220,6 +237,7 @@ private void changeHadoopInstallPathPerm(String decompressPackageName) { + "/logs/userlogs"); ShellUtils.exceShell( " chmod 775 " + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + "/logs/userlogs"); - ShellUtils.exceShell(" ln -s " + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + " " + Constants.INSTALL_PATH + Constants.SLASH + "hadoop"); + ShellUtils.exceShell(" ln -s " + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + " " + + Constants.INSTALL_PATH + Constants.SLASH + "hadoop"); } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/handler/ServiceHandler.java b/datasophon-worker/src/main/java/com/datasophon/worker/handler/ServiceHandler.java index 0da35e78..8afdc973 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/handler/ServiceHandler.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/handler/ServiceHandler.java @@ -25,33 +25,35 @@ import com.datasophon.common.utils.PropertyUtils; import com.datasophon.common.utils.ShellUtils; import com.datasophon.worker.utils.TaskConstants; -import lombok.Data; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Objects; -@Data -public class ServiceHandler { +import lombok.Data; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +@Data +public class ServiceHandler { + private String serviceName; - + private String serviceRoleName; - + private Logger logger; - + public ServiceHandler(String serviceName, String serviceRoleName) { this.serviceName = serviceName; this.serviceRoleName = serviceRoleName; String loggerName = String.format("%s-%s-%s", TaskConstants.TASK_LOG_LOGGER_NAME, serviceName, serviceRoleName); logger = LoggerFactory.getLogger(loggerName); } - + public ExecResult start(ServiceRoleRunner startRunner, ServiceRoleRunner statusRunner, String decompressPackageName, RunAs runAs) { ExecResult statusResult = execRunner(statusRunner, decompressPackageName, null); @@ -89,7 +91,7 @@ public ExecResult start(ServiceRoleRunner startRunner, ServiceRoleRunner statusR } return startResult; } - + public ExecResult stop(ServiceRoleRunner runner, ServiceRoleRunner statusRunner, String decompressPackageName, RunAs runAs) { ExecResult statusResult = execRunner(statusRunner, decompressPackageName, runAs); @@ -125,17 +127,17 @@ public ExecResult stop(ServiceRoleRunner runner, ServiceRoleRunner statusRunner, } return execResult; } - + public ExecResult reStart(ServiceRoleRunner runner, String decompressPackageName) { ExecResult result = execRunner(runner, decompressPackageName, null); return result; } - + public ExecResult status(ServiceRoleRunner runner, String decompressPackageName) { ExecResult result = execRunner(runner, decompressPackageName, null); return result; } - + public ExecResult execRunner(ServiceRoleRunner runner, String decompressPackageName, RunAs runAs) { String shell = runner.getProgram(); List args = runner.getArgs(); @@ -150,7 +152,8 @@ public ExecResult execRunner(ServiceRoleRunner runner, String decompressPackageN || runner.getProgram().contains(Constants.JOB_MANAGER)) { logger.info("do not use sh"); } else { - File shellFile = new File(Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + Constants.SLASH + shell); + File shellFile = new File( + Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + Constants.SLASH + shell); if (shellFile.exists()) { try { // 读取第一行,检查采用的 shell 是哪个,bash、sh ? @@ -173,8 +176,8 @@ public ExecResult execRunner(ServiceRoleRunner runner, String decompressPackageN command.add(shell); command.addAll(args); logger.info("execute shell command : {}", command); - return ShellUtils.execWithStatus(Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName, command, timeout, logger); + return ShellUtils.execWithStatus(Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName, command, + timeout, logger); } - - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogDiscriminator.java b/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogDiscriminator.java index a326f60c..bc7a5830 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogDiscriminator.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogDiscriminator.java @@ -14,31 +14,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.datasophon.worker.log; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.sift.AbstractDiscriminator; import com.datasophon.worker.utils.TaskConstants; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.sift.AbstractDiscriminator; + /** * Task Log Discriminator */ public class TaskLogDiscriminator extends AbstractDiscriminator { - + private static Logger logger = LoggerFactory.getLogger(TaskLogDiscriminator.class); - + /** * key */ private String key; - + /** * log base */ private String logBase; - + /** * logger name should be like: * Task Logger name should be like: Task-{processDefinitionId}-{processInstanceId}-{taskInstanceId} @@ -49,30 +52,30 @@ public String getDiscriminatingValue(ILoggingEvent event) { String prefix = TaskConstants.TASK_LOG_LOGGER_NAME + "-"; if (loggerName.startsWith(prefix)) { return loggerName.substring(prefix.length(), - loggerName.length()).replace("-","/"); + loggerName.length()).replace("-", "/"); } else { return "unknown_task"; } } - + @Override public void start() { started = true; } - + @Override public String getKey() { return key; } - + public void setKey(String key) { this.key = key; } - + public String getLogBase() { return logBase; } - + public void setLogBase(String logBase) { this.logBase = logBase; } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogFilter.java b/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogFilter.java index f7cb4caf..d8a82c4d 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogFilter.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/log/TaskLogFilter.java @@ -17,30 +17,32 @@ package com.datasophon.worker.log; +import com.datasophon.worker.utils.TaskConstants; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import ch.qos.logback.classic.Level; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.filter.Filter; import ch.qos.logback.core.spi.FilterReply; -import com.datasophon.worker.utils.TaskConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * task log filter */ public class TaskLogFilter extends Filter { - + private static Logger logger = LoggerFactory.getLogger(TaskLogFilter.class); - + /** * level */ private Level level; - + public void setLevel(String level) { this.level = Level.toLevel(level); } - + /** * Accept or reject based on thread name * diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/AbstractHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/AbstractHandlerStrategy.java index faaeefdf..75ab20d7 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/AbstractHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/AbstractHandlerStrategy.java @@ -18,23 +18,26 @@ package com.datasophon.worker.strategy; import com.datasophon.worker.utils.TaskConstants; + import lombok.Data; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Data public class AbstractHandlerStrategy { + public String serviceName; - + public String serviceRoleName; - + public Logger logger; - - public AbstractHandlerStrategy(String serviceName,String serviceRoleName) { + + public AbstractHandlerStrategy(String serviceName, String serviceRoleName) { this.serviceName = serviceName; this.serviceRoleName = serviceRoleName; String loggerName = String.format("%s-%s-%s", TaskConstants.TASK_LOG_LOGGER_NAME, serviceName, serviceRoleName); logger = LoggerFactory.getLogger(loggerName); } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/BEHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/BEHandlerStrategy.java index d9bdcb67..4887c298 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/BEHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/BEHandlerStrategy.java @@ -17,10 +17,6 @@ package com.datasophon.worker.strategy; -import akka.actor.ActorRef; -import cn.hutool.core.net.NetUtil; -import com.datasophon.common.Constants; -import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.OlapOpsType; import com.datasophon.common.command.OlapSqlExecCommand; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -30,22 +26,23 @@ import com.datasophon.worker.handler.ServiceHandler; import com.datasophon.worker.utils.ActorUtils; +import akka.actor.ActorRef; +import cn.hutool.core.net.NetUtil; public class BEHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { - - - public BEHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); + + public BEHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); - + if (command.getCommandType().equals(CommandType.INSTALL_SERVICE)) { logger.info("add be to cluster"); - + startResult = serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); if (startResult.getExecResult()) { diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DSMasterHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DSMasterHandlerStrategy.java index 8bd0f058..b491df35 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DSMasterHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DSMasterHandlerStrategy.java @@ -17,11 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.file.FileReader; -import cn.hutool.db.DbUtil; -import cn.hutool.db.ds.simple.SimpleDataSource; -import cn.hutool.db.handler.RsHandler; -import cn.hutool.db.sql.SqlExecutor; import com.datasophon.common.Constants; import com.datasophon.common.command.ServiceRoleOperateCommand; import com.datasophon.common.enums.CommandType; @@ -37,12 +32,18 @@ import java.util.List; import java.util.Optional; -public class DSMasterHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.file.FileReader; +import cn.hutool.db.DbUtil; +import cn.hutool.db.ds.simple.SimpleDataSource; +import cn.hutool.db.handler.RsHandler; +import cn.hutool.db.sql.SqlExecutor; +public class DSMasterHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public DSMasterHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); @@ -55,15 +56,20 @@ public ExecResult handler(ServiceRoleOperateCommand command) { File envFile = new File(workPath + "/bin/env/dolphinscheduler_env.sh"); if (envFile.exists()) { List lines = FileReader.create(envFile).readLines(); - Optional optionalUrl = lines.stream().filter(line -> line.contains("SPRING_DATASOURCE_URL")).findFirst(); - Optional optionaUsername = lines.stream().filter(line -> line.contains("SPRING_DATASOURCE_USERNAME")).findFirst(); - Optional optionalPassword = lines.stream().filter(line -> line.contains("SPRING_DATASOURCE_PASSWORD")).findFirst(); - + Optional optionalUrl = + lines.stream().filter(line -> line.contains("SPRING_DATASOURCE_URL")).findFirst(); + Optional optionaUsername = + lines.stream().filter(line -> line.contains("SPRING_DATASOURCE_USERNAME")).findFirst(); + Optional optionalPassword = + lines.stream().filter(line -> line.contains("SPRING_DATASOURCE_PASSWORD")).findFirst(); + if (optionalUrl.isPresent() && optionaUsername.isPresent() && optionalPassword.isPresent()) { Connection con = null; try { - con = DbUtil.use(new SimpleDataSource(getValue(optionalUrl.get()), getValue(optionaUsername.get()), getValue(optionalPassword.get()))).getConnection(); - List entityList = SqlExecutor.query(con, "SHOW TABLES", new RsHandler>(){ + con = DbUtil.use(new SimpleDataSource(getValue(optionalUrl.get()), + getValue(optionaUsername.get()), getValue(optionalPassword.get()))).getConnection(); + List entityList = SqlExecutor.query(con, "SHOW TABLES", new RsHandler>() { + @Override public List handle(ResultSet rs) throws SQLException { final List result = new ArrayList<>(); @@ -73,7 +79,8 @@ public List handle(ResultSet rs) throws SQLException { return result; } }); - if (entityList.stream().noneMatch(s -> s.equals("t_escheduler_version") || s.equals("t_ds_version") || s.equals("t_escheduler_queue"))) { + if (entityList.stream().noneMatch(s -> s.equals("t_escheduler_version") + || s.equals("t_ds_version") || s.equals("t_escheduler_queue"))) { ready = false; } } catch (SQLException sqle) { @@ -83,7 +90,7 @@ public List handle(ResultSet rs) throws SQLException { } } } - + if (!ready) { ArrayList commands = new ArrayList<>(); commands.add("bash"); @@ -97,11 +104,11 @@ public List handle(ResultSet rs) throws SQLException { } } } - + return serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); } - + private String getValue(String line) { String value = line.substring(line.indexOf("=") + 1); if (value.startsWith("\"")) { @@ -109,5 +116,5 @@ private String getValue(String line) { } return value; } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DataNodeHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DataNodeHandlerStrategy.java index 4e2cd561..3e6fa243 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DataNodeHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/DataNodeHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -29,12 +28,14 @@ import java.sql.SQLException; import java.util.ArrayList; -public class DataNodeHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; +public class DataNodeHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public DataNodeHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { ExecResult startResult = new ExecResult(); @@ -49,10 +50,12 @@ public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException String hadoopConfDir = Constants.INSTALL_PATH + Constants.SLASH + command.getDecompressPackageName() + "/etc/hadoop/"; if (!FileUtil.exist(hadoopConfDir + "ssl-server.xml")) { - ShellUtils.exceShell("cp " + hadoopConfDir + "ssl-server.xml.template " + hadoopConfDir + "ssl-server.xml"); + ShellUtils.exceShell( + "cp " + hadoopConfDir + "ssl-server.xml.template " + hadoopConfDir + "ssl-server.xml"); } if (!FileUtil.exist(hadoopConfDir + "ssl-client.xml")) { - ShellUtils.exceShell("cp " + hadoopConfDir + "ssl-client.xml.template " + hadoopConfDir + "ssl-client.xml"); + ShellUtils.exceShell( + "cp " + hadoopConfDir + "ssl-client.xml.template " + hadoopConfDir + "ssl-client.xml"); } if (!FileUtil.exist("/etc/security/keytab/keystore")) { ArrayList commands = new ArrayList<>(); @@ -73,5 +76,5 @@ public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException } return startResult; } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEHandlerStrategy.java index 811d6ac7..859d8b0c 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEHandlerStrategy.java @@ -17,11 +17,6 @@ package com.datasophon.worker.strategy; -import akka.actor.ActorRef; -import cn.hutool.core.net.NetUtil; -import cn.hutool.json.JSONUtil; -import com.datasophon.common.Constants; -import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.OlapOpsType; import com.datasophon.common.command.OlapSqlExecCommand; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -34,16 +29,21 @@ import java.util.ArrayList; -public class FEHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import akka.actor.ActorRef; - public FEHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); - } +import cn.hutool.core.net.NetUtil; +import cn.hutool.json.JSONUtil; +public class FEHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + public FEHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); + } + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); - logger.info("FEHandlerStrategy start fe"+ JSONUtil.toJsonStr(command)); + logger.info("FEHandlerStrategy start fe" + JSONUtil.toJsonStr(command)); ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); if (command.getCommandType() == CommandType.INSTALL_SERVICE) { if (command.isSlave()) { @@ -52,7 +52,7 @@ public ExecResult handler(ServiceRoleOperateCommand command) { commands.add("--helper"); commands.add(command.getMasterHost() + ":9010"); commands.add("--daemon"); - + ServiceRoleRunner startRunner = new ServiceRoleRunner(); startRunner.setProgram(command.getStartRunner().getProgram()); startRunner.setArgs(commands); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEObserverHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEObserverHandlerStrategy.java index 1d4e4e4b..cd0ae1b9 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEObserverHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FEObserverHandlerStrategy.java @@ -17,11 +17,6 @@ package com.datasophon.worker.strategy; -import akka.actor.ActorRef; -import cn.hutool.core.net.NetUtil; -import cn.hutool.json.JSONUtil; -import com.datasophon.common.Constants; -import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.OlapOpsType; import com.datasophon.common.command.OlapSqlExecCommand; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -34,12 +29,17 @@ import java.util.ArrayList; -public class FEObserverHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import akka.actor.ActorRef; +import cn.hutool.core.net.NetUtil; +import cn.hutool.json.JSONUtil; + +public class FEObserverHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public FEObserverHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); @@ -51,7 +51,7 @@ public ExecResult handler(ServiceRoleOperateCommand command) { commands.add("--helper"); commands.add(command.getMasterHost() + ":9010"); commands.add("--daemon"); - + ServiceRoleRunner startRunner = new ServiceRoleRunner(); startRunner.setProgram(command.getStartRunner().getProgram()); startRunner.setArgs(commands); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FlinkHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FlinkHandlerStrategy.java index 6eaf2ff2..a952acad 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FlinkHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/FlinkHandlerStrategy.java @@ -1,15 +1,17 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; import com.datasophon.common.utils.ExecResult; import com.datasophon.worker.utils.KerberosUtils; + +import java.sql.SQLException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.SQLException; +import cn.hutool.core.io.FileUtil; /** * flink @@ -17,16 +19,17 @@ * @author zhangkeyu * @since 2024-02-02 22:30 */ -public class FlinkHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy{ +public class FlinkHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + private static final Logger logger = LoggerFactory.getLogger(FlinkHandlerStrategy.class); - + public FlinkHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { - + if (command.getEnableKerberos()) { logger.info("start to get flink keytab file"); String hostname = CacheUtils.getString(Constants.HOSTNAME); @@ -34,7 +37,7 @@ public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException if (!FileUtil.exist("/etc/security/keytab/flink.keytab")) { KerberosUtils.downloadKeytabFromMaster("flink/" + hostname, "flink.keytab"); } - + } ExecResult startResult = new ExecResult(); startResult.setExecResult(true); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HbaseHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HbaseHandlerStrategy.java index 7637ea04..a1a977d3 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HbaseHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HbaseHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -30,12 +29,14 @@ import java.util.ArrayList; -public class HbaseHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; +public class HbaseHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public HbaseHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); @@ -75,8 +76,8 @@ public ExecResult handler(ServiceRoleOperateCommand command) { } startResult = serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); - + return startResult; - + } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HistoryServerHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HistoryServerHandlerStrategy.java index d7dc8861..bb898f42 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HistoryServerHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HistoryServerHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -27,12 +26,14 @@ import com.datasophon.worker.handler.ServiceHandler; import com.datasophon.worker.utils.KerberosUtils; -public class HistoryServerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; - public HistoryServerHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); +public class HistoryServerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + public HistoryServerHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HiveServer2HandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HiveServer2HandlerStrategy.java index 73086413..7ce4f644 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HiveServer2HandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/HiveServer2HandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -30,12 +29,14 @@ import java.util.ArrayList; -public class HiveServer2HandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; +public class HiveServer2HandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public HiveServer2HandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); @@ -70,7 +71,8 @@ public ExecResult handler(ServiceRoleOperateCommand command) { commands.add("mysql"); commands.add("-initSchema"); ExecResult execResult = ShellUtils.execWithStatus( - Constants.INSTALL_PATH + Constants.SLASH + command.getDecompressPackageName(), commands, 60L, logger); + Constants.INSTALL_PATH + Constants.SLASH + command.getDecompressPackageName(), commands, 60L, + logger); if (execResult.getExecResult()) { logger.info("init hive schema success"); } else { @@ -90,21 +92,22 @@ public ExecResult handler(ServiceRoleOperateCommand command) { String hadoopHome = PropertyUtils.getString("HADOOP_HOME"); ShellUtils.exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -mkdir -p /user/hive/warehouse"); ShellUtils.exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -mkdir -p /tmp/hive"); - ShellUtils.exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -mkdir -p /tmp/hadoop-yarn/staging/history/done"); + ShellUtils.exceShell( + "sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -mkdir -p /tmp/hadoop-yarn/staging/history/done"); ShellUtils.exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -chown -R hdfs:hadoop /tmp"); ShellUtils.exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -chmod -R 775 /tmp"); ShellUtils .exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -chown hive:hadoop /user/hive/warehouse"); ShellUtils.exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -chown hive:hadoop /tmp/hive"); ShellUtils.exceShell("sudo -u hdfs " + hadoopHome + "/bin/hdfs dfs -chmod 777 /tmp/hive"); - + // 存在 tez 则创建软连接 final String tezHomePath = Constants.INSTALL_PATH + Constants.SLASH + "tez"; if (FileUtil.exist(tezHomePath)) { ShellUtils.exceShell("ln -s " + tezHomePath + "/conf/tez-site.xml " + workPath + "/conf/tez-site.xml"); } } - + startResult = serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); return startResult; diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/JournalNodeHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/JournalNodeHandlerStrategy.java index 6c41bfeb..12d37e53 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/JournalNodeHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/JournalNodeHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -29,12 +28,14 @@ import java.sql.SQLException; import java.util.ArrayList; -public class JournalNodeHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; +public class JournalNodeHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public JournalNodeHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { ExecResult startResult = new ExecResult(); @@ -46,10 +47,12 @@ public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException String hadoopConfDir = Constants.INSTALL_PATH + Constants.SLASH + command.getDecompressPackageName() + "/etc/hadoop/"; if (!FileUtil.exist(hadoopConfDir + "ssl-server.xml")) { - ShellUtils.exceShell("cp " + hadoopConfDir + "ssl-server.xml.template " + hadoopConfDir + "ssl-server.xml"); + ShellUtils.exceShell( + "cp " + hadoopConfDir + "ssl-server.xml.template " + hadoopConfDir + "ssl-server.xml"); } if (!FileUtil.exist(hadoopConfDir + "ssl-client.xml")) { - ShellUtils.exceShell("cp " + hadoopConfDir + "ssl-client.xml.template " + hadoopConfDir + "ssl-client.xml"); + ShellUtils.exceShell( + "cp " + hadoopConfDir + "ssl-client.xml.template " + hadoopConfDir + "ssl-client.xml"); } if (!FileUtil.exist("/etc/security/keytab/jn.service.keytab")) { KerberosUtils.downloadKeytabFromMaster("jn/" + hostname, "jn.service.keytab"); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KAdminHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KAdminHandlerStrategy.java index 108b0fbf..c489c339 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KAdminHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KAdminHandlerStrategy.java @@ -26,11 +26,11 @@ import java.sql.SQLException; public class KAdminHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { - - public KAdminHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); + + public KAdminHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { ExecResult startResult = new ExecResult(); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KafkaHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KafkaHandlerStrategy.java index 285d66c3..de3af575 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KafkaHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KafkaHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -25,12 +24,14 @@ import com.datasophon.worker.handler.ServiceHandler; import com.datasophon.worker.utils.KerberosUtils; -public class KafkaHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; - public KafkaHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); +public class KafkaHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + public KafkaHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/Krb5KdcHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/Krb5KdcHandlerStrategy.java index 882ec113..ec8eed73 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/Krb5KdcHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/Krb5KdcHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.command.ServiceRoleOperateCommand; import com.datasophon.common.enums.CommandType; @@ -28,13 +27,14 @@ import java.sql.SQLException; import java.util.ArrayList; -public class Krb5KdcHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; +public class Krb5KdcHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public Krb5KdcHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - - + @Override public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { ExecResult startResult = new ExecResult(); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KyuubiServerHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KyuubiServerHandlerStrategy.java index cba3d4b0..e307788f 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KyuubiServerHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/KyuubiServerHandlerStrategy.java @@ -1,45 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; import com.datasophon.common.utils.ExecResult; import com.datasophon.worker.handler.ServiceHandler; import com.datasophon.worker.utils.KerberosUtils; -import java.sql.SQLException; - -/** - * @author thomasgx - * @date 2023年10月20日 19:02 - */ -public class KyuubiServerHandlerStrategy extends AbstractHandlerStrategy implements - ServiceRoleStrategy { - private static final String KEYTAB_NAME = "kyuubi.service.keytab"; - private static final String KEYTAB_PATH = "/etc/security/keytab/" + KEYTAB_NAME; +import java.sql.SQLException; - public KyuubiServerHandlerStrategy(String serviceName, String serviceRoleName) { - super(serviceName, serviceRoleName); - } +import cn.hutool.core.io.FileUtil; - @Override - public ExecResult handler(ServiceRoleOperateCommand command) - throws SQLException, ClassNotFoundException { - ExecResult startResult; - if (command.getEnableKerberos()) { - logger.info("start to get kyuubi keytab file"); - String hostname = CacheUtils.getString(Constants.HOSTNAME); - KerberosUtils.createKeytabDir(); - if (!FileUtil.exist(KEYTAB_PATH)) { - KerberosUtils.downloadKeytabFromMaster("kyuubi/" + hostname, KEYTAB_NAME); - } +public class KyuubiServerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + private static final String KEYTAB_NAME = "kyuubi.service.keytab"; + private static final String KEYTAB_PATH = "/etc/security/keytab/" + KEYTAB_NAME; + + public KyuubiServerHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); + } + + @Override + public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { + ExecResult startResult; + if (command.getEnableKerberos()) { + logger.info("start to get kyuubi keytab file"); + String hostname = CacheUtils.getString(Constants.HOSTNAME); + KerberosUtils.createKeytabDir(); + if (!FileUtil.exist(KEYTAB_PATH)) { + KerberosUtils.downloadKeytabFromMaster("kyuubi/" + hostname, KEYTAB_NAME); + } + } + ServiceHandler serviceHandler = new ServiceHandler( + command.getServiceName(), + command.getServiceRoleName()); + startResult = serviceHandler.start( + command.getStartRunner(), + command.getStatusRunner(), + command.getDecompressPackageName(), + command.getRunAs()); + return startResult; } - - ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), - command.getServiceRoleName()); - startResult = serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), - command.getDecompressPackageName(), command.getRunAs()); - return startResult; - } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NameNodeHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NameNodeHandlerStrategy.java index 1dffebd5..25a99f87 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NameNodeHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NameNodeHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -29,12 +28,14 @@ import java.util.ArrayList; -public class NameNodeHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; +public class NameNodeHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + public NameNodeHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); @@ -78,7 +79,8 @@ public ExecResult handler(ServiceRoleOperateCommand command) { commands.add("sh"); commands.add(workPath + "/ranger-hdfs-plugin/enable-hdfs-plugin.sh"); if (!FileUtil.exist(workPath + "/ranger-hdfs-plugin/success.id")) { - ExecResult execResult = ShellUtils.execWithStatus(workPath + "/ranger-hdfs-plugin", commands, 30L, logger); + ExecResult execResult = + ShellUtils.execWithStatus(workPath + "/ranger-hdfs-plugin", commands, 30L, logger); if (execResult.getExecResult()) { logger.info("Enable ranger hdfs plugin success"); // 写入ranger plugin集成成功标识 @@ -102,8 +104,8 @@ public ExecResult handler(ServiceRoleOperateCommand command) { } ExecResult startResult = serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); - + return startResult; } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NodeManagerHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NodeManagerHandlerStrategy.java index dc40eff9..1b13bfac 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NodeManagerHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/NodeManagerHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -27,12 +26,14 @@ import java.sql.SQLException; -public class NodeManagerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; - public NodeManagerHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); +public class NodeManagerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + public NodeManagerHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { ExecResult startResult = new ExecResult(); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/RangerAdminHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/RangerAdminHandlerStrategy.java index 4b738205..7fc0b194 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/RangerAdminHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/RangerAdminHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -25,12 +24,14 @@ import com.datasophon.worker.handler.ServiceHandler; import com.datasophon.worker.utils.KerberosUtils; -public class RangerAdminHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; - public RangerAdminHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); +public class RangerAdminHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + public RangerAdminHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); @@ -48,8 +49,8 @@ public ExecResult handler(ServiceRoleOperateCommand command) { } startResult = serviceHandler.start(command.getStartRunner(), command.getStatusRunner(), command.getDecompressPackageName(), command.getRunAs()); - + return startResult; } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ResourceManagerHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ResourceManagerHandlerStrategy.java index c66fb1c3..1564c13f 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ResourceManagerHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ResourceManagerHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -29,12 +28,14 @@ import java.sql.SQLException; -public class ResourceManagerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; - public ResourceManagerHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); +public class ResourceManagerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + public ResourceManagerHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException { ExecResult startResult = new ExecResult(); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategy.java index a5fb499b..29461030 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategy.java @@ -23,6 +23,6 @@ import java.sql.SQLException; public interface ServiceRoleStrategy { - + public ExecResult handler(ServiceRoleOperateCommand command) throws SQLException, ClassNotFoundException; } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategyContext.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategyContext.java index d63361db..3788eeab 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategyContext.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ServiceRoleStrategyContext.java @@ -17,15 +17,15 @@ package com.datasophon.worker.strategy; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class ServiceRoleStrategyContext { - + private static final Map map = new ConcurrentHashMap<>(); - + static { map.put("NameNode", new NameNodeHandlerStrategy("HDFS", "NameNode")); map.put("ZKFC", new ZKFCHandlerStrategy("HDFS", "ZKFC")); @@ -47,19 +47,18 @@ public class ServiceRoleStrategyContext { map.put("SRBE", new BEHandlerStrategy("STARROCKS", "SRBE")); map.put("DorisBE", new BEHandlerStrategy("DORIS", "DorisBE")); map.put("HistoryServer", new HistoryServerHandlerStrategy("YARN", "HistoryServer")); - + // TEZ Server service map.put("TezServer", new TezServerHandlerStrategy("TEZ", "TezServer")); - //kyuubi + // kyuubi map.put("KyuubiServer", new KyuubiServerHandlerStrategy("KYUUBI", "KyuubiServer")); - //flink + // flink map.put("FlinkClient", new FlinkHandlerStrategy("FLINK", "FlinkClient")); - - //DolphinScheduler + + // DolphinScheduler map.put("MasterServer", new DSMasterHandlerStrategy("DS", "MasterServer")); - } - + public static ServiceRoleStrategy getServiceRoleHandler(String type) { if (StringUtils.isBlank(type)) { return null; diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/TezServerHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/TezServerHandlerStrategy.java index d81c7b2b..a2313232 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/TezServerHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/TezServerHandlerStrategy.java @@ -24,7 +24,8 @@ import com.datasophon.common.utils.PropertyUtils; import com.datasophon.common.utils.ShellUtils; import com.datasophon.worker.handler.ServiceHandler; -import org.apache.commons.lang.StringUtils; + +import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; @@ -40,18 +41,19 @@ * @author zhenqin */ public class TezServerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { - + public TezServerHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ServiceHandler serviceHandler = new ServiceHandler(command.getServiceName(), command.getServiceRoleName()); String workPath = Constants.INSTALL_PATH + Constants.SLASH + command.getDecompressPackageName(); if (command.getCommandType().equals(CommandType.INSTALL_SERVICE)) { final String hadoopHome = PropertyUtils.getString("HADOOP_HOME"); - final String tezLibPath = Optional.ofNullable(StringUtils.trimToNull(createEnvPath(workPath))).orElse("hdfs:///user/tez/tez.tar.gz"); + final String tezLibPath = Optional.ofNullable(StringUtils.trimToNull(createEnvPath(workPath))) + .orElse("hdfs:///user/tez/tez.tar.gz"); final String tezLibParentDir = new Path(URI.create(tezLibPath).getPath()).getParent().toString(); logger.info("Start to execute hdfs dfs -mkdir {}", tezLibParentDir); ArrayList commands = new ArrayList<>(); @@ -65,7 +67,7 @@ public ExecResult handler(ServiceRoleOperateCommand command) { commands.add(tezLibParentDir); ExecResult execResult = ShellUtils.execWithStatus(workPath, commands, 90, logger); logger.info("mkdir {} output: {}", tezLibParentDir, execResult.getExecOut()); - + // 改变文件组权限 if (Objects.nonNull(command.getRunAs()) && StringUtils.isNotBlank(command.getRunAs().getUser())) { commands = new ArrayList<>(); @@ -80,7 +82,7 @@ public ExecResult handler(ServiceRoleOperateCommand command) { execResult = ShellUtils.execWithStatus(workPath, commands, 90, logger); logger.info("chown {} output: {}", tezLibParentDir, execResult.getExecOut()); } - + logger.info("Start to execute hdfs dfs -put ./share/tez.tar.gz {}", tezLibParentDir); commands = new ArrayList<>(); if (Objects.nonNull(command.getRunAs()) && StringUtils.isNotBlank(command.getRunAs().getUser())) { @@ -100,8 +102,7 @@ public ExecResult handler(ServiceRoleOperateCommand command) { command.getDecompressPackageName(), command.getRunAs()); return startResult; } - - + /** * tez 的元数据 * @@ -115,7 +116,7 @@ String createEnvPath(final String workPath) { conf.addResource(tezSiteFile.toURL()); logger.info("add tez-site file: {}", tezSiteFile.getAbsolutePath()); } - + // tez lib uri 启动清理 String tezLibPath = conf.get("tez.lib.uris"); return tezLibPath; diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZKFCHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZKFCHandlerStrategy.java index 0099bb1d..912b3e79 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZKFCHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZKFCHandlerStrategy.java @@ -27,11 +27,11 @@ import java.util.ArrayList; public class ZKFCHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { - + public ZKFCHandlerStrategy(String serviceName, String serviceRoleName) { super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); @@ -39,7 +39,7 @@ public ExecResult handler(ServiceRoleOperateCommand command) { String workPath = Constants.INSTALL_PATH + Constants.SLASH + command.getDecompressPackageName(); if (!command.isSlave() && command.getCommandType().equals(CommandType.INSTALL_SERVICE)) { logger.info("start to execute hdfs zkfc -formatZK"); - + ArrayList commands = new ArrayList<>(); commands.add(workPath + "/bin/hdfs"); commands.add("zkfc"); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZkServerHandlerStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZkServerHandlerStrategy.java index e509fc8c..804d4fcb 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZkServerHandlerStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/ZkServerHandlerStrategy.java @@ -17,7 +17,6 @@ package com.datasophon.worker.strategy; -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.cache.CacheUtils; import com.datasophon.common.command.ServiceRoleOperateCommand; @@ -25,12 +24,14 @@ import com.datasophon.worker.handler.ServiceHandler; import com.datasophon.worker.utils.KerberosUtils; -public class ZkServerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { +import cn.hutool.core.io.FileUtil; - public ZkServerHandlerStrategy(String serviceName,String serviceRoleName) { - super(serviceName,serviceRoleName); +public class ZkServerHandlerStrategy extends AbstractHandlerStrategy implements ServiceRoleStrategy { + + public ZkServerHandlerStrategy(String serviceName, String serviceRoleName) { + super(serviceName, serviceRoleName); } - + @Override public ExecResult handler(ServiceRoleOperateCommand command) { ExecResult startResult = new ExecResult(); @@ -53,5 +54,5 @@ public ExecResult handler(ServiceRoleOperateCommand command) { } return startResult; } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/AppendLineStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/AppendLineStrategy.java index 10a8884e..5f55698a 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/AppendLineStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/AppendLineStrategy.java @@ -1,28 +1,28 @@ package com.datasophon.worker.strategy.resource; - -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.ObjectUtil; import com.datasophon.common.Constants; -import lombok.Data; -import lombok.EqualsAndHashCode; import java.io.File; import java.nio.charset.Charset; import java.util.List; +import lombok.Data; +import lombok.EqualsAndHashCode; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ObjectUtil; + @EqualsAndHashCode(callSuper = true) @Data public class AppendLineStrategy extends ResourceStrategy { - + public static final String APPEND_LINE_TYPE = "append_line"; - + private String source; - + private Integer line; - + private String text; - + @Override public void exec() { File file = new File(basePath + Constants.SLASH + source); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/DownloadStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/DownloadStrategy.java index ba6db3d1..58bf8402 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/DownloadStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/DownloadStrategy.java @@ -1,30 +1,30 @@ package com.datasophon.worker.strategy.resource; - -import cn.hutool.core.map.MapUtil; -import cn.hutool.http.HttpUtil; import com.datasophon.common.Constants; import com.datasophon.common.utils.FileUtils; import com.datasophon.common.utils.PropertyUtils; + +import java.io.File; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; - -import java.io.File; +import cn.hutool.core.map.MapUtil; +import cn.hutool.http.HttpUtil; @Slf4j @EqualsAndHashCode(callSuper = true) @Data public class DownloadStrategy extends ResourceStrategy { - + public static final String DOWNLOAD_TYPE = "download"; - + private String from; - + private String to; - + private String md5; - + @Override public void exec() { File file = new File(basePath + Constants.SLASH + to); @@ -32,20 +32,20 @@ public void exec() { log.info("resource {} existed", to); return; } - + log.info("start to download resource : {}", from); - + String masterHost = PropertyUtils.getString(Constants.MASTER_HOST); String masterPort = PropertyUtils.getString(Constants.MASTER_WEB_PORT); String params = HttpUtil.toParams(MapUtil.builder("frameCode", frameCode) .put("serviceRoleName", serviceRole) .put("resource", from) .build()); - + String url = "http://" + masterHost + ":" + masterPort + "/ddh/service/install/downloadResource?" + params; HttpUtil.downloadFile(url, file, 300); - + log.info("end to download resource {} to {} ", from, to); } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/EmptyStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/EmptyStrategy.java index c309c8a6..ea475f2f 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/EmptyStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/EmptyStrategy.java @@ -1,15 +1,14 @@ package com.datasophon.worker.strategy.resource; - import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data public class EmptyStrategy extends ResourceStrategy { - + @Override public void exec() { - + } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/LinkStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/LinkStrategy.java index 41353fea..49e5a772 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/LinkStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/LinkStrategy.java @@ -1,26 +1,26 @@ package com.datasophon.worker.strategy.resource; - -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; import com.datasophon.common.utils.ShellUtils; + +import java.io.File; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; - -import java.io.File; +import cn.hutool.core.io.FileUtil; @Slf4j @EqualsAndHashCode(callSuper = true) @Data public class LinkStrategy extends ResourceStrategy { - + public static final String LINK_TYPE = "link"; - + private String source; - + private String target; - + @Override public void exec() { String realTarget = basePath + Constants.SLASH + target; diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ReplaceStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ReplaceStrategy.java index 431877cf..e49b95d5 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ReplaceStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ReplaceStrategy.java @@ -1,38 +1,34 @@ package com.datasophon.worker.strategy.resource; - -import cn.hutool.core.io.FileUtil; import com.datasophon.common.Constants; -import lombok.Data; -import lombok.EqualsAndHashCode; import java.io.File; import java.nio.charset.Charset; import java.util.List; import java.util.stream.Collectors; +import lombok.Data; +import lombok.EqualsAndHashCode; +import cn.hutool.core.io.FileUtil; + @EqualsAndHashCode(callSuper = true) @Data public class ReplaceStrategy extends ResourceStrategy { - + public static final String REPLACE_TYPE = "replace"; - - + private String source; - + private String regex; - + private String replacement; - - + @Override public void exec() { File file = new File(basePath + Constants.SLASH + source); if (file.exists()) { List lines = FileUtil.readLines(file, Charset.defaultCharset()) - .stream().map(line -> - line.replaceAll(regex, replacement) - ).collect(Collectors.toList()); + .stream().map(line -> line.replaceAll(regex, replacement)).collect(Collectors.toList()); FileUtil.writeLines(lines, file, Charset.defaultCharset(), false); } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ResourceStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ResourceStrategy.java index 2d4d1af2..7c2aca46 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ResourceStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ResourceStrategy.java @@ -4,17 +4,17 @@ @Data public abstract class ResourceStrategy { - + public static final String TYPE_KEY = "type"; - + String frameCode; - + String service; - + String serviceRole; - + String basePath; - + public abstract void exec(); - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ShellStrategy.java b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ShellStrategy.java index 122cb27b..4cb1c7a1 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ShellStrategy.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/strategy/resource/ShellStrategy.java @@ -1,29 +1,28 @@ package com.datasophon.worker.strategy.resource; -import com.datasophon.common.Constants; import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.ShellUtils; + +import java.util.List; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; -import java.util.Collections; -import java.util.List; - @Slf4j @EqualsAndHashCode(callSuper = true) @Data public class ShellStrategy extends ResourceStrategy { - + public static final String SHELL_TYPE = "sh"; - + private List> commands; - + @Override public void exec() { for (List command : commands) { ExecResult result = ShellUtils.execWithStatus(basePath, command, 60L); - log.info(" {} result {} ", command, result.getExecResult()? "success": "fail"); + log.info(" {} result {} ", command, result.getExecResult() ? "success" : "fail"); } } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/utils/ActorUtils.java b/datasophon-worker/src/main/java/com/datasophon/worker/utils/ActorUtils.java index 59e9decb..4143c4fc 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/utils/ActorUtils.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/utils/ActorUtils.java @@ -12,13 +12,13 @@ import akka.util.Timeout; public class ActorUtils { - + private static ActorSystem actorSystem; - + public static void setActorSystem(ActorSystem actorSystem) { ActorUtils.actorSystem = actorSystem; } - + public static ActorRef getRemoteActor(String hostname, String actorName) { String actorPath = "akka.tcp://datasophon@" + hostname + ":2551/user/" + actorName; ActorSelection actorSelection = actorSystem.actorSelection(actorPath); @@ -30,7 +30,7 @@ public static ActorRef getRemoteActor(String hostname, String actorName) { } catch (Exception e) { e.printStackTrace(); } - + return actorRef; } } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/utils/FileUtils.java b/datasophon-worker/src/main/java/com/datasophon/worker/utils/FileUtils.java index 278b6504..ca417c94 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/utils/FileUtils.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/utils/FileUtils.java @@ -23,7 +23,7 @@ import java.util.Arrays; public class FileUtils { - + /** * 读取文件最后几行
* 相当于Linux系统中的tail命令 读取大小限制是2GB @@ -58,5 +58,5 @@ public static String readLastRows(String filename, Charset charset, int rows) th return new String(tempbytes, charset); } } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/utils/FreemakerUtils.java b/datasophon-worker/src/main/java/com/datasophon/worker/utils/FreemakerUtils.java index b3197de0..2b2d9e29 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/utils/FreemakerUtils.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/utils/FreemakerUtils.java @@ -17,12 +17,11 @@ package com.datasophon.worker.utils; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.StrUtil; import com.datasophon.common.Constants; import com.datasophon.common.model.AlertItem; import com.datasophon.common.model.Generators; import com.datasophon.common.model.ServiceConfig; + import freemarker.cache.ClassTemplateLoader; import freemarker.cache.FileTemplateLoader; import freemarker.cache.MultiTemplateLoader; @@ -30,9 +29,8 @@ import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.FileWriter; @@ -43,16 +41,22 @@ import java.util.Map; import java.util.stream.Collectors; -public class FreemakerUtils { +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; - private static final Logger logger = LoggerFactory.getLogger(FreemakerUtils.class); +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; +public class FreemakerUtils { + + private static final Logger logger = LoggerFactory.getLogger(FreemakerUtils.class); + public static void generateConfigFile(Generators generators, List configs, String decompressPackageName) throws IOException, TemplateException { generateConfigFile(generators, configs, decompressPackageName, null); } - + /** * * 支持 从附加的目录加载 模版 @@ -79,7 +83,7 @@ public static void generateConfigFile(Generators generators, loaderList.add(new FileTemplateLoader(new File(extPath))); } config.setTemplateLoader(new MultiTemplateLoader(loaderList.toArray(new TemplateLoader[0]))); - + Map data = new HashMap<>(); // 得到模板对象 String configFormat = generators.getConfigFormat(); @@ -110,8 +114,7 @@ public static void generateConfigFile(Generators generators, // 3.产生输出 processOut(generators, template, data, decompressPackageName); } - - + public static void generatePromAlertFile(Generators generators, List configs, String serviceName) throws IOException, TemplateException { // 创建核心配置对象 @@ -122,18 +125,18 @@ public static void generatePromAlertFile(Generators generators, List // 得到模板对象 String configFormat = generators.getConfigFormat(); Template template = null; - + if (Constants.PROMETHEUS.equals(configFormat)) { template = config.getTemplate("alert.yml"); } - + Map data = new HashMap<>(); data.put("itemList", configs); data.put("serviceName", serviceName); // 3.产生输出 processOut(generators, template, data, "prometheus-2.17.2"); } - + public static void generatePromScrapeConfig(Generators generators, List configs, String serviceName) throws IOException, TemplateException { // 创建核心配置对象 @@ -143,18 +146,18 @@ public static void generatePromScrapeConfig(Generators generators, List data = new HashMap<>(); data.put("itemList", configs); // 3.产生输出 processOut(generators, template, data, serviceName); } - + private static void processOut(Generators generators, Template template, Map data, String decompressPackageName) throws IOException, TemplateException { String packagePath = Constants.INSTALL_PATH + Constants.SLASH + decompressPackageName + Constants.SLASH; String outputDirectory = generators.getOutputDirectory(); - + if (outputDirectory.contains(Constants.COMMA)) { for (String outPutDir : generators.getOutputDirectory().split(StrUtil.COMMA)) { String outputFile = packagePath + outPutDir + Constants.SLASH + generators.getFilename(); @@ -169,7 +172,7 @@ private static void processOut(Generators generators, Template template, Map data, String outputFile) throws IOException, TemplateException { File file = new File(outputFile); @@ -180,5 +183,5 @@ private static void writeToTemplate(Template template, Map data, template.process(data, out); out.close(); } - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/utils/KerberosUtils.java b/datasophon-worker/src/main/java/com/datasophon/worker/utils/KerberosUtils.java index 64fb473a..f74d4536 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/utils/KerberosUtils.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/utils/KerberosUtils.java @@ -28,38 +28,38 @@ import cn.hutool.http.HttpUtil; public class KerberosUtils { - + public static void downloadKeytabFromMaster(String principal, String keytabName) { String masterHost = PropertyUtils.getString(Constants.MASTER_HOST); String masterPort = PropertyUtils.getString(Constants.MASTER_WEB_PORT); Integer clusterId = PropertyUtils.getInt("clusterId"); String hostname = CacheUtils.getString("hostname"); - + // get kerberos keytab String downloadUrl = "http://" + masterHost + ":" + masterPort + "/ddh/cluster/kerberos/downloadKeytab?clusterId=" + clusterId + "&principal=" + principal + "&keytabName=" + keytabName + "&hostname=" + hostname; - + String dest = "/etc/security/keytab/"; HttpUtil.downloadFile(downloadUrl, FileUtil.file(dest), new StreamProgress() { - + @Override public void start() { Console.log("start to install。。。。"); } - + @Override public void progress(long progressSize, long l1) { Console.log("installed:{}", FileUtil.readableFileSize(progressSize)); } - + @Override public void finish() { Console.log("install success!"); } }); } - + public static void createKeytabDir() { if (!FileUtil.exist("/etc/security/keytab/")) { FileUtil.mkdir("/etc/security/keytab/"); diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/utils/TaskConstants.java b/datasophon-worker/src/main/java/com/datasophon/worker/utils/TaskConstants.java index d972e3b5..9f0dfea0 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/utils/TaskConstants.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/utils/TaskConstants.java @@ -18,99 +18,93 @@ package com.datasophon.worker.utils; public class TaskConstants { - + private TaskConstants() { throw new IllegalStateException("Utility class"); } - + public static final String YARN_APPLICATION_REGEX = "application_\\d+_\\d+"; - + public static final String FLINK_APPLICATION_REGEX = "JobID \\w+"; - + public static final String SETVALUE_REGEX = "[\\$#]\\{setValue\\(([^)]*)\\)}"; - + /** * string false */ public static final String STRING_FALSE = "false"; - + /** * exit code kill */ public static final int EXIT_CODE_KILL = 137; public static final String PID = "pid"; - + /** * QUESTION ? */ public static final String QUESTION = "?"; - + /** * comma , */ public static final String COMMA = ","; - + /** * hyphen */ public static final String HYPHEN = "-"; - + /** * slash / */ public static final String SLASH = "/"; - + /** * COLON : */ public static final String COLON = ":"; - + /** * SPACE " " */ public static final String SPACE = " "; - + /** * SINGLE_SLASH / */ public static final String SINGLE_SLASH = "/"; - - - + /** * pstree, get pud and sub pid */ public static final String PSTREE = "pstree"; - + public static final String RWXR_XR_X = "rwxr-xr-x"; - + /** * task log info format */ public static final String TASK_LOG_LOGGER_NAME = "TaskLogLogger"; - + /** * task log logger name format */ public static final String TASK_LOG_LOGGER_NAME_FORMAT = TASK_LOG_LOGGER_NAME + "-%s"; - + /** * Task Logger's prefix */ public static final String TASK_LOGGER_INFO_PREFIX = "TASK"; - + /** * Task Logger Thread's name */ public static final String TASK_APPID_LOG_FORMAT = "taskAppId"; - + /** * get output log service */ public static final String GET_OUTPUT_LOG_SERVICE = "-getOutputLogService"; - - - - - + } diff --git a/datasophon-worker/src/main/java/com/datasophon/worker/utils/UnixUtils.java b/datasophon-worker/src/main/java/com/datasophon/worker/utils/UnixUtils.java index efbef2f0..1e226a7d 100644 --- a/datasophon-worker/src/main/java/com/datasophon/worker/utils/UnixUtils.java +++ b/datasophon-worker/src/main/java/com/datasophon/worker/utils/UnixUtils.java @@ -21,7 +21,7 @@ import com.datasophon.common.utils.ExecResult; import com.datasophon.common.utils.ShellUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; @@ -29,11 +29,11 @@ import org.slf4j.LoggerFactory; public class UnixUtils { - - private static Long TIMEOUT = 60L; - + + private static final Long TIME_OUT = 60L; + private static final Logger logger = LoggerFactory.getLogger(UnixUtils.class); - + public static ExecResult createUnixUser(String username, String mainGroup, String otherGroups) { ArrayList commands = new ArrayList<>(); if (isUserExists(username)) { @@ -50,25 +50,25 @@ public static ExecResult createUnixUser(String username, String mainGroup, Strin commands.add("-G"); commands.add(otherGroups); } - return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIMEOUT); + return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIME_OUT); } - + public static ExecResult delUnixUser(String username) { ArrayList commands = new ArrayList<>(); commands.add("userdel"); commands.add("-r"); commands.add(username); - return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIMEOUT); + return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIME_OUT); } - + public static boolean isUserExists(String username) { ArrayList commands = new ArrayList<>(); commands.add("id"); commands.add(username); - ExecResult execResult = ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIMEOUT); + ExecResult execResult = ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIME_OUT); return execResult.getExecResult(); } - + public static ExecResult createUnixGroup(String groupName) { if (isGroupExists(groupName)) { ExecResult execResult = new ExecResult(); @@ -78,19 +78,19 @@ public static ExecResult createUnixGroup(String groupName) { ArrayList commands = new ArrayList<>(); commands.add("groupadd"); commands.add(groupName); - return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIMEOUT); + return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIME_OUT); } - + public static ExecResult delUnixGroup(String groupName) { ArrayList commands = new ArrayList<>(); commands.add("groupdel"); commands.add(groupName); - return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIMEOUT); + return ShellUtils.execWithStatus(Constants.INSTALL_PATH, commands, TIME_OUT); } - + public static boolean isGroupExists(String groupName) { ExecResult execResult = ShellUtils.exceShell("egrep \"" + groupName + "\" /etc/group >& /dev/null"); return execResult.getExecResult(); } - + } diff --git a/datasophon-worker/src/test/com/datasophon/worker/handler/ConfigureServiceHandlerTest.java b/datasophon-worker/src/test/com/datasophon/worker/handler/ConfigureServiceHandlerTest.java index ca75a84b..33faa7d4 100644 --- a/datasophon-worker/src/test/com/datasophon/worker/handler/ConfigureServiceHandlerTest.java +++ b/datasophon-worker/src/test/com/datasophon/worker/handler/ConfigureServiceHandlerTest.java @@ -15,7 +15,7 @@ public class ConfigureServiceHandlerTest { @BeforeAll public void setUp() { - configureServiceHandlerUnderTest = new ConfigureServiceHandler("HDFS","NameNode"); + configureServiceHandlerUnderTest = new ConfigureServiceHandler("HDFS", "NameNode"); } @Test diff --git a/datasophon-worker/src/test/com/datasophon/worker/handler/InstallServiceHandlerTest.java b/datasophon-worker/src/test/com/datasophon/worker/handler/InstallServiceHandlerTest.java index 53c9c577..5eb6fa6d 100644 --- a/datasophon-worker/src/test/com/datasophon/worker/handler/InstallServiceHandlerTest.java +++ b/datasophon-worker/src/test/com/datasophon/worker/handler/InstallServiceHandlerTest.java @@ -9,7 +9,7 @@ public class InstallServiceHandlerTest { @BeforeAll public void setUp() { - installServiceHandlerUnderTest = new InstallServiceHandler("DDP-1.2.2", "HDFS","NameNode"); + installServiceHandlerUnderTest = new InstallServiceHandler("DDP-1.2.2", "HDFS", "NameNode"); } @Test diff --git a/datasophon-worker/src/test/com/datasophon/worker/test/FreemarkerTest.java b/datasophon-worker/src/test/com/datasophon/worker/test/FreemarkerTest.java index 2cfd689d..96df381d 100644 --- a/datasophon-worker/src/test/com/datasophon/worker/test/FreemarkerTest.java +++ b/datasophon-worker/src/test/com/datasophon/worker/test/FreemarkerTest.java @@ -34,7 +34,7 @@ public void generateCustomTemplate() throws IOException, TemplateException { serviceConfigs.add(serviceConfig); serviceConfigs.add(serviceConfig2); - FreemakerUtils.generateConfigFile(generators,serviceConfigs,""); + FreemakerUtils.generateConfigFile(generators, serviceConfigs, ""); } @@ -63,6 +63,7 @@ public void generatePRCustomTemplate() throws IOException, TemplateException { nodeServiceConfigs.add(nodeServiceConfig); } + @Test public void generateSRCustomTemplate() throws IOException, TemplateException { @@ -94,7 +95,7 @@ public void generateSRCustomTemplate() throws IOException, TemplateException { beServiceConfig.setConfigType("map"); serviceConfigs.add(feServiceConfig); serviceConfigs.add(beServiceConfig); - configFileMap.put(generators,serviceConfigs); + configFileMap.put(generators, serviceConfigs); } @@ -107,13 +108,13 @@ public void generateFairSchdulerXml() throws IOException, TemplateException { generators.setTemplateName("fair-scheduler.ftl"); ArrayList queueList = new ArrayList<>(); JSONObject queue = new JSONObject(); - queue.put("queueName","test6"); - queue.put("minResources","1cores,1024mb"); - queue.put("maxResources","4cores,4096mb"); - queue.put("amShare","0.1"); - queue.put("weight",1); - queue.put("schedulePolicy","fair"); - queue.put("appNum",4); + queue.put("queueName", "test6"); + queue.put("minResources", "1cores,1024mb"); + queue.put("maxResources", "4cores,4096mb"); + queue.put("amShare", "0.1"); + queue.put("weight", 1); + queue.put("schedulePolicy", "fair"); + queue.put("appNum", 4); queueList.add(queue); ServiceConfig serviceConfig = new ServiceConfig(); serviceConfig.setName("queueList"); @@ -125,7 +126,7 @@ public void generateFairSchdulerXml() throws IOException, TemplateException { serviceConfigs.add(serviceConfig); - FreemakerUtils.generateConfigFile(generators,serviceConfigs,""); + FreemakerUtils.generateConfigFile(generators, serviceConfigs, ""); } @Test @@ -146,8 +147,9 @@ public void generateCustomTemplate1() throws IOException, TemplateException { serviceConfigs.add(serviceConfig); serviceConfigs.add(serviceConfig2); - FreemakerUtils.generateConfigFile(generators,serviceConfigs,""); + FreemakerUtils.generateConfigFile(generators, serviceConfigs, ""); } + @Test public void generateHadoopEnv() throws IOException, TemplateException { Generators generators = new Generators(); @@ -180,7 +182,7 @@ public void generateHadoopEnv() throws IOException, TemplateException { serviceConfigs.add(serviceConfig2); serviceConfigs.add(serviceConfig3); serviceConfigs.add(serviceConfig4); - FreemakerUtils.generateConfigFile(generators,serviceConfigs,""); + FreemakerUtils.generateConfigFile(generators, serviceConfigs, ""); } @Test @@ -222,7 +224,7 @@ public void testKrb5Ftl() throws IOException, TemplateException { serviceConfigs.add(serviceConfig3); serviceConfigs.add(serviceConfig4); serviceConfigs.add(serviceConfig5); - FreemakerUtils.generateConfigFile(generators,serviceConfigs,""); + FreemakerUtils.generateConfigFile(generators, serviceConfigs, ""); } diff --git a/datasophon-worker/src/test/com/datasophon/worker/test/MutilTemplateFileTest.java b/datasophon-worker/src/test/com/datasophon/worker/test/MutilTemplateFileTest.java index 8e8375ba..ef782f23 100644 --- a/datasophon-worker/src/test/com/datasophon/worker/test/MutilTemplateFileTest.java +++ b/datasophon-worker/src/test/com/datasophon/worker/test/MutilTemplateFileTest.java @@ -39,6 +39,6 @@ public void generateCustomTemplate() throws IOException, TemplateException { serviceConfigs.add(serviceConfig); serviceConfigs.add(serviceConfig2); - FreemakerUtils.generateConfigFile(generators, serviceConfigs,"", "mytemplates"); + FreemakerUtils.generateConfigFile(generators, serviceConfigs, "", "mytemplates"); } } diff --git a/docs/zh/ApacheKyuubi.md b/docs/zh/ApacheKyuubi.md index 6c108b89..f872fbb5 100644 --- a/docs/zh/ApacheKyuubi.md +++ b/docs/zh/ApacheKyuubi.md @@ -1,8 +1,8 @@ -# ApacheKyuubi +# ApacheKyuubi ## 概述 ` - ApacheKyuubi是一个分布式多租户网关,支持Spark,Flink,Hive等计算引擎, +ApacheKyuubi是一个分布式多租户网关,支持Spark,Flink,Hive等计算引擎, 依赖Kyuubi我们可以更方便的对数据湖组件进行集成. ` ## 连接器说明 @@ -11,7 +11,7 @@ ` ## 服务认证 ` - ApacheKyuubi对于认证支持多种方式,默认对Kerberos做了集成,只需要在安装时打开相关选项即可,如果 +ApacheKyuubi对于认证支持多种方式,默认对Kerberos做了集成,只需要在安装时打开相关选项即可,如果 需要集成其他认证模式可以参考:https://kyuubi.readthedocs.io/en/v1.7.3/security/index.html ` ## 权限集成 @@ -65,4 +65,3 @@ _HOST是通配) 这里只列举简单的说明与基本使用方式,ApacheKyuubi的功能远不止于此,更详细的操作请参考官方文档:https://kyuubi.readthedocs.io/en/v1.7.3 ``` - diff --git "a/docs/zh/Kerberos\345\242\236\345\212\240\347\224\250\346\210\267.md" "b/docs/zh/Kerberos\345\242\236\345\212\240\347\224\250\346\210\267.md" index 24edfea4..3fa753b7 100644 --- "a/docs/zh/Kerberos\345\242\236\345\212\240\347\224\250\346\210\267.md" +++ "b/docs/zh/Kerberos\345\242\236\345\212\240\347\224\250\346\210\267.md" @@ -43,8 +43,6 @@ other::r-x [root@master bin]# hadoop fs -setfacl -R -m user:lzy:rwx / ``` - - 3. hive和impala 用hive管理员登录 @@ -124,5 +122,3 @@ serviceName=kafka; }; ``` - - diff --git "a/docs/zh/dataSophon\345\215\207\347\272\247\345\210\260hive3.1.3+spark3.3.4\345\271\266\351\205\215\347\275\256hive on spark \346\250\241\345\274\217.md" "b/docs/zh/dataSophon\345\215\207\347\272\247\345\210\260hive3.1.3+spark3.3.4\345\271\266\351\205\215\347\275\256hive on spark \346\250\241\345\274\217.md" index 79a3a0f8..919df2d7 100644 --- "a/docs/zh/dataSophon\345\215\207\347\272\247\345\210\260hive3.1.3+spark3.3.4\345\271\266\351\205\215\347\275\256hive on spark \346\250\241\345\274\217.md" +++ "b/docs/zh/dataSophon\345\215\207\347\272\247\345\210\260hive3.1.3+spark3.3.4\345\271\266\351\205\215\347\275\256hive on spark \346\250\241\345\274\217.md" @@ -1,17 +1,21 @@ # 为DataSophon升级hive3.1.0到hive3.1.3,同时spark升级到3.3.4并集成配置hive on spark 模式 ### 下载编译配置好的hive3.1.3安装包和spark3.3.4安装包(已放入百度云盘)修改以下参数 + ``` 链接:https://pan.baidu.com/s/1Wpj8fDDuct8pwBh4IVcb_Q?pwd=soph 提取码:soph ``` + ### 将hive3.1.3.tar.gz和hive3.1.3.tar.gz.md5上传到DataSophon的安装包中 + ```shell cp ./hive3.1.3.tar.gz /opt/datasophon/DDP/packages/ cp ./hive3.1.3.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` ### 将spark-3.3.4.tar.gz和spark-3.3.4.tar.gz.md5上传到DataSophon的安装包中 + ```shell cp ./spark-3.3.4.tar.gz /opt/datasophon/DDP/packages/ cp ./spark-3.3.4.tar.gz.md5 /opt/datasophon/DDP/packages/ @@ -19,8 +23,8 @@ cp ./spark-3.3.4.tar.gz.md5 /opt/datasophon/DDP/packages/ ### hive3.1.3安装包是经过改动适配的,并在里面补充了相关兼容性jar来适配(hive on spark)模式,spark3.3.4.tar.gz安装包改动较小也可自行在网络下载 - ### DataSophon修改datasophopn-manager中conf/meat/DDP-1.2.1/HIVE/service_ddl.json,修改以下参数 + ``` "version": "3.1.3", "packageName": "hive-3.1.3.tar.gz", @@ -28,6 +32,7 @@ cp ./spark-3.3.4.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` ### DataSophon修改datasophopn-manager中conf/meat/DDP-1.2.1/SPARK3/service_ddl.json,修改以下参数 + ``` "version": "3.3.4", "packageName": "spark-3.3.4.tar.gz", @@ -37,6 +42,7 @@ cp ./spark-3.3.4.tar.gz.md5 /opt/datasophon/DDP/packages/ ### 在datasophon中删除已经安装的hive服务和spark服务 ### 修改环境变量 + ```shell vim /etc/profile.d/datasophon-env.sh export SPARK_HOME=/opt/datasophon/spark-3.3.4 @@ -44,6 +50,7 @@ export HIVE_HOME=/opt/datasophon/hive-3.1.3 ``` ### 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker @@ -51,16 +58,15 @@ sh bin/datasophon-worker.sh restart worker ``` ### 主节点重启api + ```shell sh /opt/datasophon/datasophon-manager-1.2.1/bin/datasophon-api.sh restart api ``` - ### 在datasophon中安装的hive3.1.3服务和spark3.3.4服务 - - ### 上传 spark Jar 包并更换引擎 + ``` 所以当我们将任务提交到 Yarn 上进行调度时,可能会将该任务分配到其它节点,这就会导致任务无法正常运行,所以我们需要将 Spark 中的所有 Jar 包到 HDFS 上,并告知 Hive 其存储的位置,这样可以加快任务初始化的速度 这里使用纯净版的spark(spark-3.3.4-bin-without-hadoop) @@ -74,6 +80,7 @@ hadoop fs -put ./jars/* /spark-jars ``` ### 在 Hive 配置 Spark 参数 + ```shell 进入 Hive 的 conf 目录中,创建 配置Spark 配置文件,指定相关参数。 cd $HIVE_HOME/conf @@ -92,10 +99,9 @@ spark.yarn.jars hdfs://nameservice1/spark-jars/* hadoop fs -mkdir /spark-logs ``` - ### 在 Hive 的配置文件中指定 Spark jar 包的存放位置: -``` 在其中添加下列三项配置: +```在其中添加下列三项配置: spark.yarn.jars @@ -116,7 +122,6 @@ hadoop fs -mkdir /spark-logs ``` - ### 配置spark3.3.4,将hadoop相关的xml文件拷贝到spark-3.3.4的conf目录下 ```shell 不想拷贝文件的话可以直接通过创建软链接的方式 @@ -128,7 +133,9 @@ ln -s /opt/datasophon/hadoop-3.3.3/etc/hadoop/hdfs-site.xml hdfs-site.xml ``` ### 如果涉及到hdfs目录权限问题可以简单粗暴的将目录权限设置为777 + ```shell hadoop fs -chmod -R 777 /spark-logs hadoop fs -chmod -R 777 /spark-jars ``` + diff --git "a/docs/zh/datasophon\351\233\206\346\210\220Dinky.md" "b/docs/zh/datasophon\351\233\206\346\210\220Dinky.md" index d33bc8fa..78e70487 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220Dinky.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220Dinky.md" @@ -187,7 +187,6 @@ sh /opt/datasophon-manager-1.2.1/bin/datasophon-api.sh restart api ![f8532b699ebdd66fa94f2a04dc451f5b](https://github.com/javaht/datasophon/assets/54611681/327729d6-ed75-4442-b273-6460e781d8ee) - ### 4.1需要我们手动创建数据库并且运行sql ``` @@ -228,7 +227,6 @@ vim prometheus.yml 检查是否有dinky配置文件 如果没有添加 ![2c74b17dc990845b18cfb7abf7f8312c](https://github.com/javaht/datasophon/assets/54611681/e151c3c1-eedb-4ce1-86b6-4427403ff3b4) - ### 5.3 创建Grafana 模板文件 vim dinky.json @@ -959,10 +957,8 @@ vim dinky.json ![dee4fd4731a54399166c890f385697dc](https://github.com/javaht/datasophon/assets/54611681/9a18cabf-65aa-4ba5-a6e1-b22c24b3cecd) - ![12260a17477d4ade7c3c612e77f2af1c](https://github.com/javaht/datasophon/assets/54611681/3c371705-0fc9-4a73-a3d4-25903c10fcdb) - **查看datasophon数据库中t_ddh_cluster_service_dashboard表中是否原就存在dinky 如果不存在添加** ``` diff --git "a/docs/zh/datasophon\351\233\206\346\210\220Flume.md" "b/docs/zh/datasophon\351\233\206\346\210\220Flume.md" index 066ed520..77b2c997 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220Flume.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220Flume.md" @@ -1,8 +1,10 @@ ### 1、构建安装包 + 下载: [https://dlcdn.apache.org/flume/1.11.0/apache-flume-1.11.0-bin.tar.gz](https://dlcdn.apache.org/flume/1.11.0/apache-flume-1.11.0-bin.tar.gz) 构建安装包 + ```shell tar -zxvf apache-flume-1.11.0-bin.tar.gz mv apache-flume-1.11.0-bin flume-1.11.0 @@ -12,14 +14,18 @@ echo '0a96bbd5dca673835503fa2ac5ba5335' > flume-1.11.0.tar.gz.md5 # 将安装包拷贝到各worker节点目录 cp ./flume-1.11.0.tar.gz ./flume-1.11.0.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` + ### 2、新增元数据文件 + ```shell cd /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0 mkdir FLUME cd FLUME vim service_ddl.json ``` + service_ddl.json: + ```shell { "name": "FLUME", @@ -46,17 +52,23 @@ service_ddl.json: "parameters": [] } ``` + ### 3、重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api ``` + ### 4、安装测试 + datasophon页面搭建flume服务 + ```shell yum -y install nc cd /opt/datasophon/flume-1.11.0/ vim netcat.conf ``` + ```shell a1.sources = r1 a1.sinks = k1 @@ -75,6 +87,7 @@ a1.channels.c1.transactionCapacity = 100 a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 ``` + ```shell # 开启flume监听任务 bin/flume-ng agent -n a1 -c conf/ -f ./netcat.conf -Dflume.root.logger=INFO,console @@ -82,3 +95,4 @@ bin/flume-ng agent -n a1 -c conf/ -f ./netcat.conf -Dflume.root.logger=INFO,cons nc localhost 44444 # 查看日志 flume.log ``` + diff --git "a/docs/zh/datasophon\351\233\206\346\210\220Minio.md" "b/docs/zh/datasophon\351\233\206\346\210\220Minio.md" index ebb03f82..dc95e356 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220Minio.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220Minio.md" @@ -1,5 +1,7 @@ ### 1、构建minio压缩包 + 下载minio安装包:[https://dl.min.io/server/minio/release/linux-amd64/minio](https://dl.min.io/server/minio/release/linux-amd64/minio) + ```shell mkdir /opt/soft/tmp/minio-8.4.3 cd /opt/soft/tmp/minio-8.4.3 @@ -10,7 +12,9 @@ touch ./bin/start.sh touch ./bin/stop.sh touch ./bin/status.sh ``` + 创建好的编排目录格式如下: + ```shell -bin -start.sh @@ -19,7 +23,9 @@ touch ./bin/status.sh -ect -minio ``` + 编写 stop.sh 和 status.sh + ```shell #!/bin/bash @@ -37,6 +43,7 @@ fi echo "Stop Success!" ``` + ```shell #!/bin/bash @@ -53,24 +60,31 @@ else exit 1 fi ``` + 制作minio安装包 + ```shell cd /opt/soft/tmp tar czf minio-8.4.3.tar.gz minio-8.4.3 md5sum minio-8.4.3.tar.gz echo '8f766b89b11cbc15b46b9f620a20780f' > minio-8.4.3.tar.gz.md5 ``` + 将安装包拷贝到各worker节点对应目录 + ```shell cp ./minio-8.4.3.tar.gz ./minio-8.4.3.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` + ### 2、创建minio配置文件 + ```shell cd /opt/apps/datasophon/datasophon-manager-1.1.2/conf/meta/DDP-1.1.2 mkdir MINIO cd MINIO touch service_ddl.json ``` + ```shell { "name": "MINIO", @@ -196,11 +210,14 @@ touch service_ddl.json ] } ``` + 各worker几点创建minio-run.flt文件 + ```shell cd /opt/datasophon/datasophon-worker/conf/templates touch minio-run.flt ``` + ```shell #!/bin/bash @@ -214,23 +231,33 @@ export MINIO_PROMETHEUS_AUTH_TYPE=public #加入这行环境变量,“public --address "0.0.0.0:${apiPort}" --console-address ":${consolePort}" \ ${dataPaths} > /opt/datasophon/minio/minio.log 2>&1 & ``` + ### 3、重启datasophon + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker ``` + 主节点重启api + ```shell sh /opt/apps/datasophon/datasophon-manager-1.1.2/bin/datasophon-api.sh restart api ``` + 此时可以看到mysql元数据库中 t_ddh_frame_service 和 t_ddh_frame_service_role 两个表已经添加了minio的元数据。 + ### 4、安装 + 安装配置样例 ![image](https://github.com/datavane/datasophon/assets/62798940/b7ca4c46-fcb8-4c8b-b195-e2e3d32f00c2) 注意配置文件目录data文件夹必须是空的!!! + ### 5、监控 + ```shell vim /opt/datasophon/prometheus/prometheus.yml # 新增配置 @@ -240,8 +267,11 @@ vim /opt/datasophon/prometheus/prometheus.yml static_configs: - targets: ['192.168.1.54:9000','192.168.1.55:9000','192.168.1.56:9000'] ``` + 重启prometheus + ### 6、grafana + 导入模板 [https://grafana.com/grafana/dashboards/12063](https://grafana.com/grafana/dashboards/12063) datasophon mysql表 t_ddh_cluster_service_dashboard 新增图标链接 diff --git "a/docs/zh/datasophon\351\233\206\346\210\220alluxio.md" "b/docs/zh/datasophon\351\233\206\346\210\220alluxio.md" index 89bea444..cf6600f6 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220alluxio.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220alluxio.md" @@ -1,5 +1,7 @@ ### 1、构建压缩包 + 官方下载安装包 alluxio-2.9.3-bin.tar.gz + ```shell tar -zxvf alluxio-2.9.3-bin.tar.gz cd alluxio-2.9.3 @@ -10,7 +12,9 @@ mkd5sum alluxio-2.9.3.tar.gz echo 'bf0bf449ee28d0db8da56a5dba8ecee3' > alluxio-2.9.3.tar.gz.md5 cp ./alluxio-2.9.3.tar.gz ./alluxio-2.9.3.tar.gz.md5 /opt/datasophon/DDP/packages ``` + control_alluxio.sh: + ```shell #!/bin/bash @@ -125,16 +129,20 @@ else fi ``` + ### 2、配置元数据文件 + ```shell cd /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0 mkdir ALLUXIO touch service_ddl.json touch properties_value.flt ``` + 将下面两个文件放进去 servcie_ddl.json: + ```shell { "name": "ALLUXIO", @@ -400,15 +408,20 @@ servcie_ddl.json: ] } ``` + properties_value.flt: + ```shell <#list itemList as item> ${item.value} ``` + ### 3、新增worker源码Handler + 修改 com.datasophon.worker.handler.ConfigureServiceHandler 新增: + ```shell if ("AlluxioMaster".equals(serviceRoleName) && "alluxio-site.properties".equals(generators.getFilename())) { ServiceConfig serviceConfig = new ServiceConfig(); @@ -427,13 +440,14 @@ if ("AlluxioWorker".equals(serviceRoleName) && "alluxio-site.properties".equals( ![image](https://github.com/datavane/datasophon/assets/62798940/475ae77d-8865-457c-9699-dd4bff5e46f2) - 修改 com.datasophon.worker.strategy.ServiceRoleStrategyContext: + ```shell map.put("AlluxioMaster", new AlluxioHandlerStrategy("ALLUXIO", "AlluxioMaster")); ``` 创建:com.datasophon.worker.strategy.AlluxioHandlerStrategy + ```shell package com.datasophon.worker.strategy; @@ -483,15 +497,21 @@ public class AlluxioHandlerStrategy extends AbstractHandlerStrategy implements } ``` + ### 4、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker debug ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api debug ``` + ### 5、配置样例 ![image](https://github.com/datavane/datasophon/assets/62798940/bd626fec-c581-4c22-8f36-b582afbb7ea4) diff --git "a/docs/zh/datasophon\351\233\206\346\210\220clickhouse.md" "b/docs/zh/datasophon\351\233\206\346\210\220clickhouse.md" index f19c4bae..8ef74a2a 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220clickhouse.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220clickhouse.md" @@ -1,9 +1,11 @@ ### 1、构建压缩包 + 官网下载安装包 ![image](https://github.com/datavane/datasophon/assets/62798940/8e84d696-5854-41c2-9c9d-9574a6062d4a) 各安装包解压到同一个文件夹中,同时新增bin目录,bin目录中放置status.sh + ```shell #!/bin/bash @@ -15,11 +17,15 @@ else exit 1 fi ``` + 压缩部署到DDP + ### 2、worker新增ck strategy + ```java map.put("ClickHouse", new ClickHouseHandlerStrategy("CLICKHOUSE", "ClickHouse")); ``` + ```java package com.datasophon.worker.strategy; @@ -91,8 +97,11 @@ public class ClickHouseHandlerStrategy extends AbstractHandlerStrategy implement } ``` + worker打包替换旧包 + ### 3、ck元数据文件 + ```shell @@ -1696,6 +1706,7 @@ worker打包替换旧包 ``` + ```shell { "name": "CLICKHOUSE", @@ -1833,17 +1844,25 @@ worker打包替换旧包 ] } ``` + 部署元数据文件 + ### 4、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker debug ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api debug ``` + ### 5、clickhouse服务器完全卸载命令 + ```shell pkill clickhouse rm -rf /etc/clickhouse-server @@ -1855,5 +1874,7 @@ rm -rf /var/run/clickhouse-server rm -rf /opt/datasophon/clickhouse-23.9.1.1854 rm -rf /opt/datasophon/clickhouse ``` + ### 6、配置样例 -![image](https://github.com/datavane/datasophon/assets/62798940/b2915f2e-3b2e-4e06-bcfe-b40d57bd1607) \ No newline at end of file + +![image](https://github.com/datavane/datasophon/assets/62798940/b2915f2e-3b2e-4e06-bcfe-b40d57bd1607) diff --git "a/docs/zh/datasophon\351\233\206\346\210\220hbase-2.5.6.md" "b/docs/zh/datasophon\351\233\206\346\210\220hbase-2.5.6.md" index 3c83b5b7..6240d256 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220hbase-2.5.6.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220hbase-2.5.6.md" @@ -1,11 +1,11 @@ ### 1、上传安装包 + 将编译好的安装包hbase-2.5.6.tar.gz和md5文件hbase-2.5.6.tar.gz.md5放到安装包目录/opt/datasophon/DDP/packages下 ```shell scp hbase-2.5.6.tar.gz hbase-2.5.6.tar.gz.md5 /opt/datasophon/DDP/packages ``` - ### 2、修改源码HBASE的service_ddl.json,重新打包api包 代码路径是datasophon\datasophon-api\src\main\resources\meta\DDP-1.2.0\HBASE\service_ddl.json @@ -493,6 +493,7 @@ scp hbase-2.5.6.tar.gz hbase-2.5.6.tar.gz.md5 /opt/datasophon/DDP/packages ] } ``` + ### 3、修改源码的datasophon-env.sh和hbase-env.ftl,重新打包worker包 修改datasophon-env.sh,代码路径是datasophon\datasophon-worker\src\main\resources\script\datasophon-env.sh @@ -515,7 +516,8 @@ export HADOOP_CONF_DIR=/opt/datasophon/hadoop-3.3.3/etc/hadoop export PATH=$PATH:$JAVA_HOME/bin:$SPARK_HOME/bin:$HADOOP_HOME/bin:$HIVE_HOME/bin:$FLINK_HOME/bin:$KAFKA_HOME/bin:$HBASE_HOME/bin ``` - 修改hbase-env.ftl,代码路径是datasophon\datasophon-worker\src\main\resources\templates\hbase-env.ftl + +修改hbase-env.ftl,代码路径是datasophon\datasophon-worker\src\main\resources\templates\hbase-env.ftl ```shell #!/usr/bin/env bash @@ -668,28 +670,24 @@ export ${item.name}=${item.value} ``` - - ### 4、修改service源码,重新打包api包 修改ZkServerHandlerStrategy.java,代码路径是 datasophon\datasophon-service\src\main\java\com\datasophon\api\strategy\ZkServerHandlerStrategy.java,修改hamdler方法 ```java - @Override - public void handler(Integer clusterId, List hosts) { - // 保存zkUrls到全局变量 - Map globalVariables = GlobalVariables.get(clusterId); - String join = String.join(":2181,", hosts); - String zkUrls = join + ":2181"; - ProcessUtils.generateClusterVariable(globalVariables, clusterId, "${zkUrls}", zkUrls); - // 保存zkHostsUrl到全局变量 - String zkHostsUrl=String.join(",", hosts); - ProcessUtils.generateClusterVariable(globalVariables, clusterId, "${zkHostsUrl}", zkHostsUrl); - } +@Override +public void handler(Integer clusterId, List hosts) { + // 保存zkUrls到全局变量 + Map globalVariables = GlobalVariables.get(clusterId); + String join = String.join(":2181,", hosts); + String zkUrls = join + ":2181"; + ProcessUtils.generateClusterVariable(globalVariables, clusterId, "${zkUrls}", zkUrls); + // 保存zkHostsUrl到全局变量 + String zkHostsUrl=String.join(",", hosts); + ProcessUtils.generateClusterVariable(globalVariables, clusterId, "${zkHostsUrl}", zkHostsUrl); +} ``` - - ### 5、重启DataSophonApplicationServer服务 关闭原来的DataSophonApplicationServer服务 diff --git "a/docs/zh/datasophon\351\233\206\346\210\220openldap.md" "b/docs/zh/datasophon\351\233\206\346\210\220openldap.md" index baab881b..bdfa9a21 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220openldap.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220openldap.md" @@ -1,4 +1,5 @@ ### 1、构建安装包 + ```shell mkdir openldap-2.4.44-22.el7 cd openldap-2.4.44-22.el7 @@ -15,7 +16,9 @@ md5sum openldap-2.4.44-22.el7.tar.gz echo '146e20ea21a85be1182f88627f69b7e8' > openldap-2.4.44-22.el7.tar.gz.md5 cp ./openldap-2.4.44-22.el7.tar.gz ./openldap-2.4.44-22.el7.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` + add-memberof.ldif + ```shell dn: cn=module{0},cn=config cn: modulle{0} @@ -35,7 +38,9 @@ olcMemberOfRefInt: TRUE olcMemberOfGroupOC: groupOfUniqueNames olcMemberOfMemberAD: uniqueMember ``` + base.ldif + ```shell dn: dc=ldap,dc=com dc: ldap @@ -55,7 +60,9 @@ dn: ou=Group,dc=ldap,dc=com objectClass: organizationalUnit ou: Group ``` + control_openldap.sh + ```shell #!/bin/bash @@ -96,13 +103,17 @@ esac exit 0 ``` + refint1.ldif + ```shell dn: cn=module{0},cn=config add: olcmoduleload olcmoduleload: refint ``` + refint2.ldif + ```shell dn: olcOverlay=refint,olcDatabase={2}hdb,cn=config objectClass: olcConfig @@ -112,14 +123,18 @@ objectClass: top olcOverlay: refint olcRefintAttribute: memberof uniqueMember manager owner ``` + ### 2、元数据文件 + ```shell cd /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0 mkdir OPENLDAP cd OPENLDAP touch service_ddl.json ``` + service_ddl.json + ```shell { "name": "OPENLDAP", @@ -204,8 +219,11 @@ service_ddl.json ] } ``` + ### 3、新增worker策略 + 新增 com.datasophon.worker.strategy.OpenldapHandlerStrategy + ```shell package com.datasophon.worker.strategy; @@ -286,11 +304,15 @@ public class OpenldapHandlerStrategy extends AbstractHandlerStrategy implements } ``` + com.datasophon.worker.strategy.ServiceRoleStrategyContext 新增代码 + ```shell map.put("OpenldapServer", new OpenldapHandlerStrategy("OPENLDAP", "OpenldapServer")); ``` + 新增com.datasophon.api.strategy.OpenldapHandlerStrategy + ```java package com.datasophon.api.strategy; @@ -337,21 +359,31 @@ public class OpenldapHandlerStrategy implements ServiceRoleStrategy { } ``` + 修改com.datasophon.api.strategy.ServiceRoleStrategyContext + ```java map.put("OpenldapServer", new OpenldapHandlerStrategy()); ``` + 打包部署 + ### 4、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker debug ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api debug ``` + ### 5、服务器openldap服务完全清除命令 + ```shell systemctl stop slapd systemctl disable slapd @@ -361,8 +393,11 @@ rm -rf /etc/openldap/slapd.d rm -rf /opt/datasophon/openldap-2.4.44-22.el7 rm -rf /opt/datasophon/openldap ``` + ### 5、用户操作命令 + #### 5.1 添加用户 + ```shell dn: uid=user1,ou=People,dc=ldap,dc=com objectClass: top @@ -402,10 +437,13 @@ uidNumber: 1002 gidNumber: 1002 homeDirectory: /home/user2 ``` + ```shell ldapadd -x -D "cn=root,dc=ldap,dc=com" -W -f ./create.ldif ``` + #### 5.2 删除用户 + ```shell dn: uid=user1,ou=People,dc=ldap,dc=com changetype: delete @@ -413,6 +451,8 @@ changetype: delete dn: uid=user2,ou=People,dc=ldap,dc=com changetype: delete ``` + ```shell ldapmodify -x -D "cn=root,dc=ldap,dc=com" -W -f ./delete.ldif ``` + diff --git "a/docs/zh/datasophon\351\233\206\346\210\220paimon.md" "b/docs/zh/datasophon\351\233\206\346\210\220paimon.md" index b256f6bb..d96fd239 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220paimon.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220paimon.md" @@ -2,11 +2,11 @@ ### Paimon: -#### 目前支持Flink 1.14及以上版本 +#### 目前支持Flink 1.14及以上版本 -#### 目前支持 Hive 3.1、2.3、2.2、2.1 和 2.1-cdh-6.3。支持 Hive Read 的 MR 和 Tez 执行引擎,以及 Hive Write 的 MR 执行引擎(beeline也不支持hive write) +#### 目前支持 Hive 3.1、2.3、2.2、2.1 和 2.1-cdh-6.3。支持 Hive Read 的 MR 和 Tez 执行引擎,以及 Hive Write 的 MR 执行引擎(beeline也不支持hive write) -#### 目前支持 Spark 3.4、3.3、3.2 和 3.1 +#### 目前支持 Spark 3.4、3.3、3.2 和 3.1 快照仓库,根据自己需要选择集成的组件和版本:https://repository.apache.org/content/groups/snapshots/org/apache/paimon/ @@ -20,18 +20,22 @@ ### 解压flink-1.16.3安装包 -- ```shell - tar -zxvf flink-1.16.3-bin-scala_2.12.tgz(这里可以用原datasophon的1.15版本或者是参照官网的步骤定制需要的flink版本,如果用的原flink版本或者已经升级过,直接解压packages中的包即可,如果同时需要升级flink版本,注意保持和service_ddl.json中 decompressPackageName 一致) - mv flink-1.16.3-bin-scala_2.12.tgz flink-1.16.3 - ``` +- + +```shell +tar -zxvf flink-1.16.3-bin-scala_2.12.tgz(这里可以用原datasophon的1.15版本或者是参照官网的步骤定制需要的flink版本,如果用的原flink版本或者已经升级过,直接解压packages中的包即可,如果同时需要升级flink版本,注意保持和service_ddl.json中 decompressPackageName 一致) +mv flink-1.16.3-bin-scala_2.12.tgz flink-1.16.3 +``` ### 拷贝相关的包到lib目录 -- ```shell - cp paimon-flink-1.16-0.7-20231201.002224-11.jar /opt/datasophon/flink-1.16.3/lib - cp flink-sql-connector-hive-3.1.2_2.12-1.16.2.jar /opt/datasophon/flink-1.16.3/lib - ****解决乱七八糟的类找不到的问题:cp /opt/datasophon/hadoop-3.3.3/share/hadoop/mapreduce/hadoop-mapreduce-client-core-3.3.3.jar /opt/datasophon/flink-1.16.3/lib - ``` +- + +```shell +cp paimon-flink-1.16-0.7-20231201.002224-11.jar /opt/datasophon/flink-1.16.3/lib +cp flink-sql-connector-hive-3.1.2_2.12-1.16.2.jar /opt/datasophon/flink-1.16.3/lib +****解决乱七八糟的类找不到的问题:cp /opt/datasophon/hadoop-3.3.3/share/hadoop/mapreduce/hadoop-mapreduce-client-core-3.3.3.jar /opt/datasophon/flink-1.16.3/lib +``` ### 检查环境变量 @@ -101,8 +105,6 @@ SET 'sql-client.execution.result-mode' = 'tableau'; ![](C:\Users\Hasee\Desktop\paimon-catalogs.png) - - ### Hive:hive-3.1.0集成paimon 解压hive-3.1.0安装包 @@ -137,8 +139,6 @@ FROM test.test_paimon; ![image-20231203185833490](C:\Users\Hasee\AppData\Roaming\Typora\typora-user-images\image-20231203185833490.png) - - ### Spark:spark-3.2.2集成paimon ```shell diff --git "a/docs/zh/datasophon\351\233\206\346\210\220presto.md" "b/docs/zh/datasophon\351\233\206\346\210\220presto.md" index cd7a3c3d..999c0eb9 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220presto.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220presto.md" @@ -1,29 +1,40 @@ ### 1、打包安装包 + 解压安装包,可以在这里对解压后的文件做修改,更改文件名,这里的文件名是和后面的配置文件对应的: + ```shell tar -zxvf presto-server-0.283.tar.gz mv presto-server-0.283 presto-0.283 ``` + 将文件打包,注意这里的压缩包名也和后面配置文件对应: + ```shell tar czf presto-0.283.tar.gz presto-0.283 ``` + 编写md5文件: + ```shell md5sum presto-0.283.tar.gz echo '84666ba9ef9b9024fa7c385af0823101' > presto-0.283.tar.gz.md5 ``` + 将两个文件拷贝进对应文件夹中: + ```shell cp ./presto-0.283.tar.gz ./presto-0.283.tar.gz.md5 /opt/datasophon/DDP/packages ``` + ### 2、编写presto元数据 + ```shell cd /opt/apps/datasophon/datasophon-manager-1.1.2/conf/meta/DDP-1.1.2 mkdir PRESTO cd PRESTO vim service_ddl.json ``` + ```shell { "name": "PRESTO", @@ -282,10 +293,12 @@ vim service_ddl.json ] } ``` + ```shell cd /opt/datasophon/datasophon-worker/conf/templates vim presto.jvm.config.ftl ``` + ```shell -server -Xmx${prestoHeapSize}G @@ -303,41 +316,53 @@ vim presto.jvm.config.ftl -XX:+UnlockDiagnosticVMOptions -XX:+UseAESCTRIntrinsics ``` + ### 3、修改worker源码,重新打包worker包 + 修改 datasophon-worker/src/main/java/com/datasophon/worker/handler/ConfigureServiceHandler.java 新增代码 ![image](https://github.com/datavane/datasophon/assets/62798940/0fbf7d09-e351-4789-9aff-f911610e117f) ```shell - if ("PrestoCoordinator".equals(serviceRoleName) && "coordinator".equals(config.getName())) { - logger.info("Start config presto coordinator"); - config.setValue("true"); - ServiceConfig serviceConfig = new ServiceConfig(); - serviceConfig.setName("node-scheduler.include-coordinator"); - serviceConfig.setValue("false"); - ServiceConfig serviceConfig1 = new ServiceConfig(); - serviceConfig1.setName("discovery-server.enabled"); - serviceConfig1.setValue("true"); - customConfList.add(serviceConfig); - customConfList.add(serviceConfig1); - } +if ("PrestoCoordinator".equals(serviceRoleName) && "coordinator".equals(config.getName())) { + logger.info("Start config presto coordinator"); + config.setValue("true"); + ServiceConfig serviceConfig = new ServiceConfig(); + serviceConfig.setName("node-scheduler.include-coordinator"); + serviceConfig.setValue("false"); + ServiceConfig serviceConfig1 = new ServiceConfig(); + serviceConfig1.setName("discovery-server.enabled"); + serviceConfig1.setValue("true"); + customConfList.add(serviceConfig); + customConfList.add(serviceConfig1); +} ``` + 将重新打包的 datasophon-worker-1.1.2.jar 文件替换到每个worker节点的 /opt/datasophon/datasophon-worker/lib 1.2.0版本worker包名为datasophon-worker-1.1.3.jar,需要上传后改名 + ### 4、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker ``` + 主节点重启api + ```shell sh /opt/apps/datasophon/datasophon-manager-1.1.2/bin/datasophon-api.sh restart api ``` + 此时可以看到mysql元数据库中 t_ddh_frame_service 和 t_ddh_frame_service_role 两个表已经添加了presto的元数据。 搭建需要注意一点节点不能既是master又是worker + ### 5、集成监控 + #### 5.1 presto安装目录创建jmx配置文件 + ```shell pwd /opt/datasophon/presto @@ -345,6 +370,7 @@ mkdir jmx cd jmx vim prometheus_config.yml ``` + ```shell --- lowercaseOutputLabelNames: true @@ -361,6 +387,7 @@ rules: type: GAUGE attrNameSnakeCase: true ``` + 将 jmx_prometheus_javaagent-0.16.1.jar 放入jmx文件夹 ![image](https://github.com/datavane/datasophon/assets/62798940/16b9dd5d-8957-45b6-b0fc-163e47d49a25) @@ -845,22 +872,28 @@ if __name__ == '__main__': main() ``` + #### 5.3 修改Prometheus配置文件 + ```shell vim /opt/datasophon/prometheus/prometheus.yml ``` + 新增presto配置 + ```shell - - job_name: 'prestocoordinator' - file_sd_configs: - - files: - - configs/prestocoordinator.json - - job_name: 'prestoworker' - file_sd_configs: - - files: - - configs/prestoworker.json +- job_name: 'prestocoordinator' + file_sd_configs: + - files: + - configs/prestocoordinator.json +- job_name: 'prestoworker' + file_sd_configs: + - files: + - configs/prestoworker.json ``` + 在 /opt/datasophon/prometheus/configs 目录新增 prestocoordinator.json 和 prestoworker.json 配置文件 + ```shell [ { @@ -868,6 +901,7 @@ vim /opt/datasophon/prometheus/prometheus.yml } ] ``` + ```shell [ { @@ -875,17 +909,20 @@ vim /opt/datasophon/prometheus/prometheus.yml } ] ``` + 重启prometheus,访问webui可看到采集过来的指标 [http://hadoop1:9090/targets](http://hadoop1:9090/targets) ![image](https://github.com/datavane/datasophon/assets/62798940/f93a3ad1-64c6-463c-b989-c7c7af93cd82) #### 5.4 绘制grafana + 打开grafana ui ![image](https://github.com/datavane/datasophon/assets/62798940/369c0997-5a5e-44ce-bcc8-5163360b240c) 将下面json粘贴进去 + ```shell { "annotations": { @@ -1834,7 +1871,9 @@ vim /opt/datasophon/prometheus/prometheus.yml "weekStart": "" } ``` + #### 5.5 添加dotasophon presto模块总览 + 在grafana中复制面板链接 ![image](https://github.com/datavane/datasophon/assets/62798940/02443af5-90ff-4dc8-9cbd-d42fee7b2ca4) @@ -1849,7 +1888,9 @@ vim /opt/datasophon/prometheus/prometheus.yml ![image](https://github.com/datavane/datasophon/assets/62798940/d15fcc17-16bf-4604-acf8-014f29ae7713) #### 5.6 集成告警 + 在 /opt/datasophon/prometheus/alert_rules 目录中添加presto告警配置文件 presto.yml + ```shell groups: - name: PRESTO @@ -1883,6 +1924,7 @@ groups: summary: 重新启动 description: "{{ $labels.job }}的{{ $labels.instance }}实例产生告警" ``` + 重启prometheus,可以在UI上看到已经添加了告警 ![image](https://github.com/datavane/datasophon/assets/62798940/75709858-b641-425c-b87f-f838a5dea1fc) diff --git "a/docs/zh/datasophon\351\233\206\346\210\220redis.md" "b/docs/zh/datasophon\351\233\206\346\210\220redis.md" index 7f995183..2d5db810 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220redis.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220redis.md" @@ -1,5 +1,7 @@ ### 1、构建安装包 + 下载redis tar包 redis-7.2.3.tar.gz + ```shell tar -zxvf redis-7.2.3.tar.gz cd redis-7.2.3 @@ -30,15 +32,20 @@ md5sum redis-7.2.3.tar.gz echo 'd20743bd570ab78efaf0a9aa3b28caf5' > redis-7.2.3.tar.gz.md5 cp ./redis-7.2.3.tar.gz ./redis-7.2.3.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` + ### 2、元数据文件 + **api节点元数据:** + ```shell cd /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0 mkdir REDIS cd REDIS touch service_ddl.json ``` + service_ddl.json: + ```shell { "name": "REDIS", @@ -237,6 +244,7 @@ service_ddl.json: ``` **各worker节点元数据:** + ```shell cd /opt/datasophon/datasophon-worker/conf/templates touch redis-cluster.ftl @@ -244,7 +252,9 @@ touch redis-control.ftl touch redis-master.ftl touch redis-slave.ftl ``` + redis-cluster.ftl: + ```shell #!/bin/bash @@ -338,7 +348,9 @@ main() { # 执行主函数 main ``` + redis-control.ftl: + ```shell #!/bin/bash @@ -437,7 +449,9 @@ case $1 in ;; esac ``` + redis-master.ftl: + ```shell bind 0.0.0.0 daemonize yes @@ -458,7 +472,9 @@ cluster-node-timeout 5000 ${item.name} ${item.value} ``` + redis-slave.ftl: + ```shell bind 0.0.0.0 daemonize yes @@ -479,8 +495,11 @@ cluster-node-timeout 5000 ${item.name} ${item.value} ``` + ### 3、修改源码 + com.datasophon.api.strategy.RedisHandlerStrategy + ```java package com.datasophon.api.strategy; @@ -553,11 +572,15 @@ public class RedisHandlerStrategy extends ServiceHandlerAbstract implements Serv } } ``` + com.datasophon.api.strategy.ServiceRoleStrategyContext + ```java map.put("REDIS", new RedisHandlerStrategy()); ``` + com.datasophon.worker.strategy.RedisHandlerStrategy + ```java package com.datasophon.worker.strategy; @@ -594,18 +617,27 @@ public class RedisHandlerStrategy extends AbstractHandlerStrategy implements Ser } } ``` + com.datasophon.worker.strategy.ServiceRoleStrategyContext + ```java map.put("RedisMaster", new RedisHandlerStrategy("REDIS", "RedisMaster")); map.put("RedisWorker", new RedisHandlerStrategy("REDIS", "RedisWorker")); ``` + **打包部署** + ### 4、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker debug ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api debug ``` + diff --git "a/docs/zh/datasophon\351\233\206\346\210\220seatunnel.md" "b/docs/zh/datasophon\351\233\206\346\210\220seatunnel.md" index 24bb5450..e1191baf 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220seatunnel.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220seatunnel.md" @@ -1,6 +1,8 @@ ### 1、构建安装包 -下载安装包 + +下载安装包 [https://www.apache.org/dyn/closer.lua/seatunnel/2.3.3/apache-seatunnel-2.3.3-bin.tar.gz](https://www.apache.org/dyn/closer.lua/seatunnel/2.3.3/apache-seatunnel-2.3.3-bin.tar.gz) + ```shell tar -zxvf apache-seatunnel-2.3.3-bin.tar.gz mv apache-seatunnel-2.3.3-bin seatunnel-2.3.3 @@ -18,6 +20,7 @@ tar czf seatunnel-2.3.3.tar.gz seatunnel-2.3.3 md5sum seatunnel-2.3.3.tar.gz echo '27c821b7d7ead2f99a4db2d7503fc2b5' > seatunnel-2.3.3.tar.gz.md5 ``` + ```shell #!/bin/bash @@ -30,14 +33,18 @@ else exit 1 fi ``` + ### 2、元数据文件 + api节点新增: + ```shell cd /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0 mkdir SEATUNNEL cd SEATUNNEL touch service_ddl.json ``` + ```shell { "name": "SEATUNNEL", @@ -147,13 +154,16 @@ touch service_ddl.json } ``` + 各worker节点新增: + ```shell cd /opt/datasophon/datasophon-worker/conf/templates touch seatunnel-yml.flt touch hazelcast.flt touch hazelcast-client.flt ``` + ```shell hazelcast: cluster-name: seatunnel @@ -183,6 +193,7 @@ hazelcast: hazelcast.logging.type: log4j2 hazelcast.operation.generic.thread.count: 50 ``` + ```shell hazelcast-client: cluster-name: seatunnel @@ -196,6 +207,7 @@ hazelcast-client: ``` + ```shell seatunnel: engine: @@ -218,15 +230,21 @@ seatunnel: ${item.name}: ${item.value} ``` + ### 3、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker debug ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api debug ``` + ### 4、页面配置样例 ![image](https://github.com/datavane/datasophon/assets/62798940/e72af3f5-cbd2-41c4-9d30-988c3cfb36ee) diff --git "a/docs/zh/datasophon\351\233\206\346\210\220zeppelin.md" "b/docs/zh/datasophon\351\233\206\346\210\220zeppelin.md" index ede97e2b..e4a36141 100644 --- "a/docs/zh/datasophon\351\233\206\346\210\220zeppelin.md" +++ "b/docs/zh/datasophon\351\233\206\346\210\220zeppelin.md" @@ -1,7 +1,9 @@ ### 1、构建安装包 + 下载安装包 zeppelin-0.10.1-bin-all.tgz [https://zeppelin.apache.org/download.html](https://zeppelin.apache.org/download.html) + ```shell tar -zxvf zeppelin-0.10.1-bin-all.tgz mv zeppelin-0.10.1-bin-all zeppelin-0.10.1 @@ -14,7 +16,9 @@ md5sum zeppelin-0.10.1.tar.gz echo 'c2e7f95d459777683c966a1d087754de' > zeppelin-0.10.1.tar.gz.md5 cp ./zeppelin-0.10.1.tar.gz ./zeppelin-0.10.1.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` + control_zeppeline.sh: + ```shell #!/bin/bash @@ -67,7 +71,9 @@ esac exit 0 ``` + ### 2、元数据文件 + ```shell # api元数据目录 cd /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0 @@ -80,7 +86,9 @@ cd /opt/datasophon/datasophon-worker/conf/templates touch zeppelin-env.ftl touch zeppelin-site.ftl ``` + service_ddl.json: + ```shell { "name": "ZEPPELIN", @@ -190,7 +198,9 @@ service_ddl.json: ] } ``` + zeppelin-env.ftl: + ```shell #!/bin/bash @@ -203,7 +213,9 @@ export JAVA_HOME=$parent_dir/jdk1.8.0_311 export ${item.name}=${item.value} ``` + zeppelin-site.ftl + ```shell @@ -1038,12 +1050,18 @@ zeppelin-site.ftl ``` + ### 3、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker debug ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api debug ``` + diff --git "a/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234dolphinscheduler-3.1.8\345\256\211\350\243\205\345\214\205.md" "b/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234dolphinscheduler-3.1.8\345\256\211\350\243\205\345\214\205.md" index 275f5a15..146743a1 100644 --- "a/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234dolphinscheduler-3.1.8\345\256\211\350\243\205\345\214\205.md" +++ "b/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234dolphinscheduler-3.1.8\345\256\211\350\243\205\345\214\205.md" @@ -1,6 +1,7 @@ # 为DataSophon制作dolphinscheduler-3.1.8安装包 ### DataSophon修改datasophopn-manager中conf/meat/DDP-1.2.0/DS/service_ddl.json,修改以下参数 + ``` "version": "3.1.8", "packageName": "dolphinscheduler-3.1.8.tar.gz", @@ -8,18 +9,25 @@ ``` ### 下载apache-dolphinscheduler-3.1.8-bin.tar.gz包,在服务器中解压缩 + ```shell tar -xvf ./apache-dolphinscheduler-3.1.8-bin.tar.gz ``` + ### 修改文件名称,主要是要与上面decompressPackageName一致 + ```shell mv apache-dolphinscheduler-3.1.8-bin dolphinscheduler-3.1.8 ``` + ### 增加jmx文件夹 + ```shell cp jmx dolphinscheduler-3.1.8 ``` + ### 修改以下脚本的启动命令使jmx生效 + ./dolphinscheduler-3.1.8/alert-server/bin/start.sh ./dolphinscheduler-3.1.8/api-server/bin/start.sh @@ -31,13 +39,16 @@ cp jmx dolphinscheduler-3.1.8 ```主要是JAVA_OPTS中添加了jmx内容 JAVA_OPTS=${JAVA_OPTS:-"-server -javaagent:$BIN_DIR/../../jmx/jmx_prometheus_javaagent-0.16.1.jar=12359:$BIN_DIR/../../jmx/prometheus_config.yml -Duser.timezone=${SPRING_JACKSON_TIME_ZONE} -Xms1g -Xmx1g -Xmn512m -XX:+PrintGCDetails -Xloggc:gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump.hprof"} ``` + ### jmx的端口号需要和service_ddl.json中的jmx端口号一致 + * api-server:12356 * master-server:12357 * worker-server:12358 * alert-server:12359 ### 修改dolphinscheduler-3.1.8/bin/dolphinscheduler-daemon.sh脚本,在几乎使最下方的地方$state == "STOP"的地方增加一行exit 1 + ```shell (status) get_server_running_status @@ -60,18 +71,25 @@ JAVA_OPTS=${JAVA_OPTS:-"-server -javaagent:$BIN_DIR/../../jmx/jmx_prometheus_jav ``` ### 增加mysql依赖包,将mysql8依赖包放入到每个组件的lib中 + 参考ds的说明https://github.com/apache/dolphinscheduler/blob/3.1.8-release/docs/docs/zh/guide/howto/datasource-setting.md ### 打压缩包 + ```shell tar -zcvf dolphinscheduler-3.1.8.tar.gz dolphinscheduler-3.1.8 ``` + ### 生成md5文件 + ```shell md5sum dolphinscheduler-3.1.8.tar.gz > dolphinscheduler-3.1.8.tar.gz.md5 ``` + ### 将dolphinscheduler-3.1.8.tar.gz和dolphinscheduler-3.1.8.tar.gz.md5上传到DataSophon的安装包中 + ```shell cp ./dolphinscheduler-3.1.8.tar.gz /opt/datasophon/DDP/packages/ cp ./dolphinscheduler-3.1.8.tar.gz.md5 /opt/datasophon/DDP/packages/ -``` \ No newline at end of file +``` + diff --git "a/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234streampark-2.1.1\345\256\211\350\243\205\345\214\205.md" "b/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234streampark-2.1.1\345\256\211\350\243\205\345\214\205.md" index 4eb4f06e..fa9c880a 100644 --- "a/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234streampark-2.1.1\345\256\211\350\243\205\345\214\205.md" +++ "b/docs/zh/\344\270\272DataSophon\345\210\266\344\275\234streampark-2.1.1\345\256\211\350\243\205\345\214\205.md" @@ -1,12 +1,15 @@ # 为DataSophon制作streampark-2.1.1安装包.md ## 下载并解压streampark 2.1.1安装包 + ```shell tar -xzvf apache-streampark_2.12-2.1.1-incubating-bin.tar.gz ``` ## 修改安装包目录名称 + 保持和service_ddl.json中 decompressPackageName 一致 + ```shell mv apache-streampark_2.12-2.1.1-incubating-bin streampark-2.1.1 ``` @@ -14,6 +17,7 @@ mv apache-streampark_2.12-2.1.1-incubating-bin streampark-2.1.1 ## 修改`streampark-2.1.1/bin/streampark.sh`文件 - 在DEFAULT_OPTS(原249行)中增加prometheus_javaagent配置,如下: + ```shell DEFAULT_OPTS=""" -ea @@ -30,22 +34,24 @@ DEFAULT_OPTS=""" """ ``` -- 在start函数中,`local workspace=...略`(原380行)下一行,增加 `mkdir-p $workspace`,如下 +- 在start函数中,`local workspace=...略`(原380行)下一行,增加 `mkdir-p $workspace`,如下 + ```shell - local workspace=$(echo "$conf_streampark_workspace_local" | sed 's/#.*$//g') - mkdir -p $workspace - if [[ ! -d $workspace ]]; then - echo_r "ERROR: streampark.workspace.local: \"$workspace\" is invalid path, Please reconfigure in application.yml" - echo_r "NOTE: \"streampark.workspace.local\" Do not set under APP_HOME($APP_HOME). Set it to a secure directory outside of APP_HOME. " +local workspace=$(echo "$conf_streampark_workspace_local" | sed 's/#.*$//g') +mkdir -p $workspace +if [[ ! -d $workspace ]]; then + echo_r "ERROR: streampark.workspace.local: \"$workspace\" is invalid path, Please reconfigure in application.yml" + echo_r "NOTE: \"streampark.workspace.local\" Do not set under APP_HOME($APP_HOME). Set it to a secure directory outside of APP_HOME. " + exit 1; +fi +if [[ ! -w $workspace ]] || [[ ! -r $workspace ]]; then + echo_r "ERROR: streampark.workspace.local: \"$workspace\" Permission denied! " exit 1; - fi - if [[ ! -w $workspace ]] || [[ ! -r $workspace ]]; then - echo_r "ERROR: streampark.workspace.local: \"$workspace\" Permission denied! " - exit 1; - fi +fi ``` - 修改status函数(原582行)中增加`exit 1`,如下: + ```shell status() { # shellcheck disable=SC2155 @@ -61,26 +67,30 @@ status() { ``` ## 增加jmx文件夹 + ```shell - cp jmx streampark-2.1.1 +cp jmx streampark-2.1.1 ``` ## copy mysql8驱动包至lib目录 + (streampark从某个版本后把mysql驱动包移除了) + ```shell cp mysql-connector-java-8.0.28.jar streampark-2.1.1/lib/ ``` ## copy streampark安装包内的 mysql-schema.sql 和 mysql-data.sql 脚本出来备用 + ```shell cp streampark-2.1.1/script/schema/mysql-schema.sql ./streampark_mysql-schema.sql cp streampark-2.1.1/script/data/mysql-data.sql ./streampark_mysql-data.sql ``` ## 打压缩包并生成md5 + ```shell tar -czf streampark-2.1.1.tar.gz streampark-2.1.1 md5sum streampark-2.1.1.tar.gz | awk '{print $1}' >streampark-2.1.1.tar.gz.md5 ``` - diff --git "a/docs/zh/\345\215\207\347\272\247flink1.15\345\210\260flink1.16.2.md" "b/docs/zh/\345\215\207\347\272\247flink1.15\345\210\260flink1.16.2.md" index 5efe15e3..65c4a507 100644 --- "a/docs/zh/\345\215\207\347\272\247flink1.15\345\210\260flink1.16.2.md" +++ "b/docs/zh/\345\215\207\347\272\247flink1.15\345\210\260flink1.16.2.md" @@ -1,5 +1,7 @@ ### 1、构建压缩包 + 下载flink官方包 flink-1.16.2-bin-scala_2.12.tgz + ```shell tar -zxvf flink-1.16.2-bin-scala_2.12.tgz tar czf flink-1.16.2.tar.gz flink-1.16.2 @@ -11,10 +13,13 @@ md5sum flink-1.16.2.tar.gz echo '8d6c243ebc9bf58d3ee3e45e5c6509f4' > flink-1.16.2.tar.gz.md5 cp ./flink-1.16.2.tar.gz ./flink-1.16.2.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` + ### 2、修改service_ddl.json + ```shell vim /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0/FLINK/service_ddl.json ``` + ```shell { "name": "FLINK", @@ -174,27 +179,39 @@ vim /opt/apps/datasophon-manager-1.2.0/conf/meta/DDP-1.2.0/FLINK/service_ddl.jso ] } ``` + ### 3、修改环境变量 + ```shell vim /etc/profile.d/datasophon-env.sh export FLINK_HOME=/opt/datasophon/flink-1.16.2 export HADOOP_CLASSPATH=`hadoop classpath` source /etc/profile.d/datasophon-env.sh ``` + 各节点同样操作 + ### 4、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api ``` + ### 5、测试 + ```shell flink run -d -t yarn-per-job $FLINK_HOME/examples/streaming/WordCount.jar ``` + ```shell flink run-application -t yarn-application $FLINK_HOME/examples/streaming/TopSpeedWindowing.jar ``` + diff --git "a/docs/zh/\345\215\207\347\272\247spark3.1\345\210\2603.2.2.md" "b/docs/zh/\345\215\207\347\272\247spark3.1\345\210\2603.2.2.md" index aaf4c767..bad89451 100644 --- "a/docs/zh/\345\215\207\347\272\247spark3.1\345\210\2603.2.2.md" +++ "b/docs/zh/\345\215\207\347\272\247spark3.1\345\210\2603.2.2.md" @@ -1,5 +1,7 @@ ### 1、构建压缩包 + 下载官方包 spark-3.2.2-bin-hadoop3.2.tgz + ```shell tar -zxvf spark-3.2.2-bin-hadoop3.2.tgz mv spark-3.2.2-bin-hadoop3.2 spark-3.2.2 @@ -13,7 +15,9 @@ md5sum spark-3.2.2.tar.gz echo 'eadd4bb2ce5d809ce4c8631f1e865252' > spark-3.2.2.tar.gz.md5 cp ./spark-3.2.2.tar.gz ./spark-3.2.2.tar.gz.md5 /opt/datasophon/DDP/packages/ ``` + ### 2、修改servcie_ddl.json + ```shell { "name": "SPARK3", @@ -120,28 +124,42 @@ cp ./spark-3.2.2.tar.gz ./spark-3.2.2.tar.gz.md5 /opt/datasophon/DDP/packages/ ] } ``` + ### 3、修改环境变量 + ```shell vim /etc/profile.d/datasophon-env.sh export SPARK_HOME=/opt/datasophon/spark-3.2.2 ``` + 各节点分发 + ### 4、重启 + 各节点worker重启 + ```shell sh /opt/datasophon/datasophon-worker/bin/datasophon-worker.sh restart worker ``` + 主节点重启api + ```shell sh /opt/apps/datasophon-manager-1.2.0/bin/datasophon-api.sh restart api ``` + ### 5、测试 + 单机: + ```shell sh /opt/datasophon/spark-3.2.2/bin/spark-submit --class org.apache.spark.examples.SparkPi /opt/datasophon/spark-3.2.2/examples/jars/spark-examples_2.12-3.2.2.jar 12 ``` + yarn: + ```shell su - hdfs sh /opt/datasophon/spark-3.2.2/bin/spark-submit --master yarn --deploy-mode client --class org.apache.spark.examples.SparkPi /opt/datasophon/spark-3.2.2/examples/jars/spark-examples_2.12-3.2.2.jar 12 ``` + diff --git a/pom.xml b/pom.xml index aafa5fa9..a52027d7 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ 1.2.1 2.4.20 3.0.1 - 2.6 + 3.12.0 1.1.14 1.2.83 5.8.9 @@ -57,11 +57,8 @@ 2.9.2 UTF-8 UTF-8 - origin/dev - 2.27.1 2.6.1 5.3.13 - 2.27.2 2.14.2 9.20.0 2.1.214 @@ -77,6 +74,9 @@ 3.2.2 0.3.0 2.23.4 + 2.27.2 + 3.4.3 + origin/dev 4.5.1 @@ -119,8 +119,8 @@ ${druid.version} - commons-lang - commons-lang + org.apache.commons + commons-lang3 ${commons.lang} @@ -295,59 +295,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.codehaus.mojo @@ -355,33 +302,133 @@ ${versions-maven-plugin.version} - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + /style/checkstyle.xml + /style/checkstyle-suppressions.xml + UTF-8 + UTF-8 + true + false + true + + ${project.build.sourceDirectory} + ${project.build.testSourceDirectory} + + **/*.properties, + **/*.sh, + **/*.bat, + **/*.yml, + **/*.yaml, + **/*.xml, + **/*.dict + **/.asf.yaml, + **/.github/**, + **/crd/**.yml, + **/crd/**.yaml + + + + + com.puppycrawl.tools + checkstyle + 8.30 + + + + + validate + + check + + process-sources + + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + style/spotless_datasophon_formatter.xml + + + + style/eclipse.importorder + + + + + UTF-8 + 4 + true + false + true + true + false + false + custom_1 + false + false + + + Leading blank line + project + project + + + + + + + + check + + compile + + + + https://datasophon.github.io/datasophon-website/ diff --git a/style/checkstyle-suppressions.xml b/style/checkstyle-suppressions.xml index 0f68384c..ec84b482 100644 --- a/style/checkstyle-suppressions.xml +++ b/style/checkstyle-suppressions.xml @@ -15,10 +15,24 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> + - + "-//Puppy Crawl//DTD Suppressions 1.1//EN" + "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> + + + + + + + + diff --git a/style/checkstyle.xml b/style/checkstyle.xml index aff912fa..68c4b2d5 100644 --- a/style/checkstyle.xml +++ b/style/checkstyle.xml @@ -18,248 +18,458 @@ + "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> + + - - + + + + + + + + + + + + + + + - + - - + + + + + + + + + - - + + + + + + + + + + + - - - - - + + + + + + - - - + - - + + + + + - - + + + + - - + + + + - - - + + + + + + + value="Use Guava Checks instead of Commons Validate. Please refer to the coding guidelines."/> + + + + + + + + + + + + + + + - - - - + + + + + + + + + - - - + + + + - - - + + - - - - - - - + + + - + + + + - + + + + + - + + + + + - + - + - - - - + + + + + - - - + + + + - + + + + + + + + + value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/> + + + + + + + + + + + + - + + + + + + + - + + + + + + + + - - + + - - - + + + - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + + - + + - - - - - - + + - - - - - - - + + + + + - + - - - + + + - - - - - + + + + + + + - - + + + + - + + + + - - - + + + + + - + + + + - + + + + + + + + + - - - + + + + - - - - - - - + + + - - diff --git a/style/spotless_datasophon_formatter.xml b/style/spotless_datasophon_formatter.xml index d9d36809..cb38761c 100644 --- a/style/spotless_datasophon_formatter.xml +++ b/style/spotless_datasophon_formatter.xml @@ -18,35 +18,33 @@ * limitations under the License. */ --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +