@Override protected Object doExecute() throws Exception { MQBrokerConfigDTO dto = createDTO(); Profile profile = MQManager.createOrUpdateProfile(dto, fabricService); String profileId = profile.getId(); System.out.println("MQ profile " + profileId + " ready"); // assign profile to existing containers if (assign != null) { String[] assignContainers = assign.split(","); MQManager.assignProfileToContainers(fabricService, profile, assignContainers); } // create containers if (create != null) { String[] createContainers = create.split(","); List<CreateContainerBasicOptions.Builder> builderList = MQManager.createContainerBuilders( dto, fabricService, "child", profileId, dto.version(), createContainers); for (CreateContainerBasicOptions.Builder builder : builderList) { CreateContainerMetadata[] metadatas = null; try { if (builder instanceof CreateChildContainerOptions.Builder) { CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder; builder = childBuilder.jmxUser(username).jmxPassword(password); } metadatas = fabricService.createContainers(builder.build()); ShellUtils.storeFabricCredentials(session, username, password); } catch (FabricAuthenticationException fae) { // If authentication fails, prompts for credentials and try again. if (builder instanceof CreateChildContainerOptions.Builder) { CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder; promptForJmxCredentialsIfNeeded(); metadatas = fabricService.createContainers( childBuilder.jmxUser(username).jmxPassword(password).build()); ShellUtils.storeFabricCredentials(session, username, password); } } } } return null; }
private MQBrokerConfigDTO createDTO() { if (Strings.isNullOrBlank(username)) { username = ShellUtils.retrieveFabricUser(session); } if (Strings.isNullOrBlank(password)) { password = ShellUtils.retrieveFabricUserPassword(session); } MQBrokerConfigDTO dto = new MQBrokerConfigDTO(); dto.setConfigUrl(config); dto.setData(data); if (ports != null && ports.length > 0) { for (String port : ports) { addConfig(port, dto.getPorts()); } } dto.setGroup(group); dto.setJvmOpts(jvmOpts); dto.setBrokerName(name); dto.setProfile(profile); dto.setClientProfile(clientProfile); dto.setClientParentProfile(clientParentProfile); dto.setNetworks(networks); dto.setNetworksPassword(networksPassword); dto.setNetworksUserName(networksUserName); dto.setParentProfile(parentProfile); dto.setProperties(properties); dto.setVersion(version); dto.setMinimumInstances(minimumInstances); dto.setReplicas(replicas); if (kind != null) { dto.setKind(kind); } return dto; }