public async Task ContinueClusterSetup() { AssertOnlyInSetupMode(); var operationCancelToken = new OperationCancelToken(ServerStore.ServerShutdown); var operationId = GetLongQueryString("operationId", false); if (operationId.HasValue == false) { operationId = ServerStore.Operations.GetNextOperationId(); } using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context)) using (var continueSetupInfoJson = context.ReadForMemory(RequestBodyStream(), "continue-cluster-setup")) { var continueSetupInfo = JsonDeserializationServer.ContinueSetupInfo(continueSetupInfoJson); await ServerStore.Operations.AddOperation( null, "Continue Cluster Setup.", Documents.Operations.Operations.OperationType.Setup, progress => SetupManager.ContinueClusterSetupTask(progress, continueSetupInfo, ServerStore, operationCancelToken.Token), operationId.Value, token : operationCancelToken); } NoContentStatus(); }
public Task ExtractInfoFromZip() { AssertOnlyInSetupMode(); using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context)) using (var continueSetupInfoJson = context.ReadForMemory(RequestBodyStream(), "continue-setup-info")) { var continueSetupInfo = JsonDeserializationServer.ContinueSetupInfo(continueSetupInfoJson); byte[] zipBytes; try { zipBytes = Convert.FromBase64String(continueSetupInfo.Zip); } catch (Exception e) { throw new ArgumentException($"Unable to parse the {nameof(continueSetupInfo.Zip)} property, expected a Base64 value", e); } try { var urlByTag = new Dictionary <string, string>(); using (var ms = new MemoryStream(zipBytes)) using (var archive = new ZipArchive(ms, ZipArchiveMode.Read, false)) { foreach (var entry in archive.Entries) { if (entry.Name.Equals("settings.json") == false) { continue; } var tag = entry.FullName.Substring(0, entry.FullName.Length - "/settings.json".Length); using (var settingsJson = context.ReadForMemory(entry.Open(), "settings-json")) if (settingsJson.TryGet(nameof(ConfigurationNodeInfo.PublicServerUrl), out string publicServerUrl)) { urlByTag[tag] = publicServerUrl; } } } using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteStartArray(); var first = true; foreach (var node in urlByTag) { if (first == false) { writer.WriteComma(); } writer.WriteStartObject(); writer.WritePropertyName(nameof(ConfigurationNodeInfo.Tag)); writer.WriteString(node.Key); writer.WriteComma(); writer.WritePropertyName(nameof(ConfigurationNodeInfo.PublicServerUrl)); writer.WriteString(node.Value); writer.WriteEndObject(); first = false; } writer.WriteEndArray(); } } catch (Exception e) { throw new InvalidOperationException("Unable to extract setup information from the zip file.", e); } } return(Task.CompletedTask); }