Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #121 from swisscom/update-service-mongodbent
Browse files Browse the repository at this point in the history
Update service for MongoDB Ent
  • Loading branch information
seilc1 committed Jun 20, 2018
2 parents d524c14 + e4a7a2f commit 709f6ac
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 53 deletions.
Expand Up @@ -10,7 +10,6 @@ import com.swisscom.cloud.sb.broker.error.ErrorCode
import com.swisscom.cloud.sb.broker.model.ProvisionRequest
import com.swisscom.cloud.sb.broker.model.ServiceDetail
import com.swisscom.cloud.sb.broker.model.ServiceInstance
import com.swisscom.cloud.sb.broker.model.UpdateRequest
import com.swisscom.cloud.sb.broker.provisioning.async.AsyncOperationResult
import com.swisscom.cloud.sb.broker.provisioning.lastoperation.LastOperationJobContext
import com.swisscom.cloud.sb.broker.provisioning.statemachine.ServiceStateWithAction
Expand All @@ -26,15 +25,13 @@ import com.swisscom.cloud.sb.broker.services.mongodb.enterprise.opsmanager.OpsMa
import com.swisscom.cloud.sb.broker.services.mongodb.enterprise.statemachine.MongoDbEnterperiseStateMachineContext
import com.swisscom.cloud.sb.broker.services.mongodb.enterprise.statemachine.MongoDbEnterpriseDeprovisionState
import com.swisscom.cloud.sb.broker.services.mongodb.enterprise.statemachine.MongoDbEnterpriseProvisionState
import com.swisscom.cloud.sb.broker.updating.UpdateResponse
import com.swisscom.cloud.sb.broker.util.servicedetail.ServiceDetailKey
import com.swisscom.cloud.sb.broker.util.servicedetail.ServiceDetailType
import com.swisscom.cloud.sb.broker.util.servicedetail.ServiceDetailsHelper
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import sun.reflect.generics.reflectiveObjects.NotImplementedException

import javax.annotation.PostConstruct

Expand Down Expand Up @@ -104,6 +101,39 @@ class MongoDbEnterpriseServiceProvider extends AsyncServiceProvider<MongoDbEnter
return mongodbConfig.opsManagerUrlForAutomationAgent ?: mongodbConfig.opsManagerUrl
}

@Override
AsyncOperationResult requestUpdate(LastOperationJobContext context) {
// verify upgrade possible
if (context.updateRequest.plan == context.updateRequest.previousPlan) {
// perform upgrade
StateMachine stateMachine = createUpdateStateMachine()
ServiceStateWithAction currentState = getUpdateState(context)
def actionResult = stateMachine.setCurrentState(currentState, createStateMachineContext(context))
return AsyncOperationResult.of(actionResult.go2NextState ? stateMachine.nextState(currentState) : currentState, actionResult.details)
} else {
// throw error for impossible upgrade
ErrorCode.SERVICE_UPDATE_NOT_ALLOWED.throwNew()
return null
}
}

@VisibleForTesting
private StateMachine createUpdateStateMachine() {
StateMachine stateMachine = new StateMachine([CHECK_AGENTS, REQUEST_AUTOMATION_UPDATE, CHECK_AUTOMATION_UPDATE_STATUS, PROVISION_SUCCESS])
return stateMachine
}

@VisibleForTesting
private ServiceStateWithAction getUpdateState(LastOperationJobContext context) {
ServiceStateWithAction provisionState = null
if (!context.lastOperation.internalState) {
provisionState = MongoDbEnterpriseProvisionState.CHECK_AGENTS
} else {
provisionState = MongoDbEnterpriseProvisionState.of(context.lastOperation.internalState)
}
return provisionState
}

@Override
AsyncOperationResult requestProvision(LastOperationJobContext context) {
StateMachine stateMachine = createProvisionStateMachine(context)
Expand Down Expand Up @@ -203,11 +233,6 @@ class MongoDbEnterpriseServiceProvider extends AsyncServiceProvider<MongoDbEnter
opsManagerFacade.deleteOpsManagerUser(ServiceDetailsHelper.from(request.binding.details).getValue(MongoDbEnterpriseServiceDetailKey.MONGODB_ENTERPRISE_OPS_MANAGER_USER_ID))
}

UpdateResponse update(UpdateRequest request) {
ErrorCode.SERVICE_UPDATE_NOT_ALLOWED.throwNew()
return null
}

public static String getMongoDbGroupId(LastOperationJobContext context) {
return getMongoDbGroupId(context.serviceInstance)
}
Expand Down
Expand Up @@ -118,24 +118,32 @@ class OpsManagerFacade {
return true
}

def MongoDbEnterpriseDeployment deployStandAlone(String groupId, String database, int port) {
MongoDbEnterpriseDeployment deployStandAlone(String groupId, String database, int port) {
throw new NotImplementedException()
}

//TODO refactor this method ,passing in too many arguments
def MongoDbEnterpriseDeployment deployReplicaSet(String groupId, String database, int port, String healthUser, String healthPassword, String mongoDbVersion) {
MongoDbEnterpriseDeployment deployReplicaSet(String groupId, String database, int port, String healthUser, String healthPassword, String mongoDbVersion, String featureCompatibilityVersion) {
final List<String> hosts = findHostsForGroup(groupId)
final List<HostPort> hostPorts = hosts.collect { String host -> new HostPort(host: host, port: port) }

MongoDbEnterpriseDeployment deployment = null
updateAutomationConfig(groupId, { AutomationConfigDto automationConfigDto ->
deployment = configureInstancesWithReplicaSetMode(database, hostPorts, automationConfigDto, healthUser, healthPassword, mongoDbVersion)
deployment = configureInstancesWithReplicaSetMode(database, hostPorts, automationConfigDto, healthUser, healthPassword, mongoDbVersion, featureCompatibilityVersion)
})

return deployment
}

def MongoDbEnterpriseDeployment deployShard(String groupId, String database, int port) {
Boolean updateReplicaSet(String groupId, String mongoDbVersion, String featureCompatibilityVersion) {
updateAutomationConfig(groupId, { AutomationConfigDto automationConfigDto ->
automationConfigDto.processes.each { it.featureCompatibilityVersion = featureCompatibilityVersion }
automationConfigDto.processes.each { it.version = mongoDbVersion }
})
return true
}

MongoDbEnterpriseDeployment deployShard(String groupId, String database, int port) {
throw new NotImplementedException()
}

Expand All @@ -149,7 +157,8 @@ class OpsManagerFacade {

private MongoDbEnterpriseDeployment configureInstancesWithReplicaSetMode(String database, List<HostPort> hostPorts, AutomationConfigDto automationConfig,
String healthUser, String healthPassword,
String mongoDbVersion) {
String mongoDbVersion,
String featureCompatibilityVersion) {
final String replicaSetId = "rs_${database}"

if (!automationConfig.options) {
Expand All @@ -166,7 +175,7 @@ class OpsManagerFacade {
HostPort hostPort, int i ->
String name = "${replicaSetId}_${i}"
String path = createDbPath(name)
ProcessDto processDto = createProcessDto(hostPort, replicaSetId, path, name, mongoDbVersion)
ProcessDto processDto = createProcessDto(hostPort, replicaSetId, path, name, mongoDbVersion, featureCompatibilityVersion)
automationConfig.processes.add(processDto)
}

Expand Down Expand Up @@ -230,12 +239,12 @@ class OpsManagerFacade {
return result
}

private ProcessDto createProcessDto(HostPort hostPort, String replicaSet, String path, String name, String mongoDbVersion) {
private ProcessDto createProcessDto(HostPort hostPort, String replicaSet, String path, String name, String mongoDbVersion, String featureCompatibilityVersion) {
ProcessDto processDto = new ProcessDto(version: mongoDbVersion,
processType: PROCESS_TYPE_MONGOD,
name: name,
authSchemaVersion: mongoDbEnterpriseConfig.authSchemaVersion,
featureCompatibilityVersion: mongoDbEnterpriseConfig.featureCompatibilityVersion,
featureCompatibilityVersion: featureCompatibilityVersion ? featureCompatibilityVersion : mongoDbEnterpriseConfig.featureCompatibilityVersion,
hostname: hostPort.host,
logRotate: createLogRotateDto(),
args2_6: new ProcessArgumentsV26Dto(net: new ProcessArgumentsV26Dto.Net(port: hostPort.port),
Expand Down Expand Up @@ -326,8 +335,8 @@ class OpsManagerFacade {
//populateKeyInfo(authenticationDto)
}

private void setAuthMechamnismIfNotAlreadySet(AuthenticationDto authenticationDto){
if(!authenticationDto.autoAuthMechanism){
private void setAuthMechamnismIfNotAlreadySet(AuthenticationDto authenticationDto) {
if (!authenticationDto.autoAuthMechanism) {
authenticationDto.autoAuthMechanism = AUTH_MECHANISM_MONGODB_CR
}
}
Expand Down

0 comments on commit 709f6ac

Please sign in to comment.