public async Task UpdateRecordSetPreconditionFailed() { var namespaceName = Recording.GenerateAssetName("sdk-RecordSet"); var cnameRecord = new CnameRecord { Cname = "www.contoso.example.com" }; var recordName = "cname_record"; var testCnameRecordSet = new RecordSet("test_id", recordName, "Cname", null, this.metadata, 60, null, null, null, this.dummyARecords, this.dummyAaaaRecords, this.dummyMxRecords, this.dummyNsRecords, this.dummyPtrRecords, this.dummySrvRecords, this.dummyTxtRecords, cnameRecord, null, this.dummyCaaRecords); var createRecordSetResponse = await RecordSetsOperations.CreateOrUpdateAsync(resourceGroup, this.zoneNameForList, recordName, RecordType.Cname, testCnameRecordSet); bool exceptionCaught = false; try { await RecordSetsOperations.CreateOrUpdateAsync( this.resourceGroup, this.zoneNameForList, recordName, RecordType.Cname, ifMatch : "somegibberish", ifNoneMatch : null, parameters : testCnameRecordSet); } catch (Azure.RequestFailedException) { exceptionCaught = true; } finally { Assert.True(exceptionCaught); } }
internal CnameRecordSetData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, string etag, IDictionary <string, string> metadata, long?ttl, string fqdn, string provisioningState, WritableSubResource targetResource, CnameRecord cnameRecord) : base(id, name, resourceType, systemData) { Etag = etag; Metadata = metadata; TTL = ttl; Fqdn = fqdn; ProvisioningState = provisioningState; TargetResource = targetResource; CnameRecord = cnameRecord; }
public static bool AreEqual(CnameRecord first, CnameRecord second) { if (first == null && second == null) { return(true); } else if (first == null || second == null) { return(false); } return(first.Cname == second.Cname); }
public static bool AreCnameRecordSetsEquivalent(CnameRecord subject, CnameRecord expected) { if (subject == null) { return(expected == null); } else if (expected == null) { return(false); } return(subject.Cname == expected.Cname); }
internal RecordSetData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, string etag, IDictionary <string, string> metadata, long?ttl, string fqdn, string provisioningState, WritableSubResource targetResource, IList <ARecord> aRecords, IList <AaaaRecord> aaaaRecords, IList <MxRecord> mxRecords, IList <NsRecord> nsRecords, IList <PtrRecord> ptrRecords, IList <SrvRecord> srvRecords, IList <TxtRecord> txtRecords, CnameRecord cnameRecord, SoaRecord soaRecord, IList <CaaRecord> caaRecords) : base(id, name, resourceType, systemData) { Etag = etag; Metadata = metadata; TTL = ttl; Fqdn = fqdn; ProvisioningState = provisioningState; TargetResource = targetResource; ARecords = aRecords; AaaaRecords = aaaaRecords; MxRecords = mxRecords; NsRecords = nsRecords; PtrRecords = ptrRecords; SrvRecords = srvRecords; TxtRecords = txtRecords; CnameRecord = cnameRecord; SoaRecord = soaRecord; CaaRecords = caaRecords; }
private void _read() { _name = new DomainName(m_io, this, m_root); _type = ((DnsPacket.RecordType)m_io.ReadU2be()); _answerClass = ((DnsPacket.ClassType)m_io.ReadU2be()); _ttl = m_io.ReadS4be(); _rdlength = m_io.ReadU2be(); switch (Type) { case DnsPacket.RecordType.Aaaa: { _rdata = new AaaaRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.A: { _rdata = new ARecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Mx: { _rdata = new MxRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Cname: { _rdata = new CnameRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Ns: { _rdata = new NsRecord(m_io, this, m_root); break; } case DnsPacket.RecordType.Ptr: { _rdata = new PtrRecord(m_io, this, m_root); break; } } }
internal static RecordSetData DeserializeRecordSetData(JsonElement element) { Optional <string> etag = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <IDictionary <string, string> > metadata = default; Optional <long> ttl = default; Optional <string> fqdn = default; Optional <string> provisioningState = default; Optional <WritableSubResource> targetResource = default; Optional <IList <ARecord> > aRecords = default; Optional <IList <AaaaRecord> > aaaaRecords = default; Optional <IList <MxRecord> > mxRecords = default; Optional <IList <NsRecord> > nsRecords = default; Optional <IList <PtrRecord> > ptrRecords = default; Optional <IList <SrvRecord> > srvRecords = default; Optional <IList <TxtRecord> > txtRecords = default; Optional <CnameRecord> cnameRecord = default; Optional <SoaRecord> soaRecord = default; Optional <IList <CaaRecord> > caaRecords = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("metadata")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, property1.Value.GetString()); } metadata = dictionary; continue; } if (property0.NameEquals("TTL")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ttl = property0.Value.GetInt64(); continue; } if (property0.NameEquals("fqdn")) { fqdn = property0.Value.GetString(); continue; } if (property0.NameEquals("provisioningState")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("targetResource")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } targetResource = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("ARecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ARecord> array = new List <ARecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ARecord.DeserializeARecord(item)); } aRecords = array; continue; } if (property0.NameEquals("AAAARecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <AaaaRecord> array = new List <AaaaRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(AaaaRecord.DeserializeAaaaRecord(item)); } aaaaRecords = array; continue; } if (property0.NameEquals("MXRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <MxRecord> array = new List <MxRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(MxRecord.DeserializeMxRecord(item)); } mxRecords = array; continue; } if (property0.NameEquals("NSRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <NsRecord> array = new List <NsRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(NsRecord.DeserializeNsRecord(item)); } nsRecords = array; continue; } if (property0.NameEquals("PTRRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <PtrRecord> array = new List <PtrRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(PtrRecord.DeserializePtrRecord(item)); } ptrRecords = array; continue; } if (property0.NameEquals("SRVRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <SrvRecord> array = new List <SrvRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(SrvRecord.DeserializeSrvRecord(item)); } srvRecords = array; continue; } if (property0.NameEquals("TXTRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <TxtRecord> array = new List <TxtRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(TxtRecord.DeserializeTxtRecord(item)); } txtRecords = array; continue; } if (property0.NameEquals("CNAMERecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } cnameRecord = CnameRecord.DeserializeCnameRecord(property0.Value); continue; } if (property0.NameEquals("SOARecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } soaRecord = SoaRecord.DeserializeSoaRecord(property0.Value); continue; } if (property0.NameEquals("caaRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <CaaRecord> array = new List <CaaRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(CaaRecord.DeserializeCaaRecord(item)); } caaRecords = array; continue; } } continue; } } return(new RecordSetData(id, name, type, systemData, etag.Value, Optional.ToDictionary(metadata), Optional.ToNullable(ttl), fqdn.Value, provisioningState.Value, targetResource, Optional.ToList(aRecords), Optional.ToList(aaaaRecords), Optional.ToList(mxRecords), Optional.ToList(nsRecords), Optional.ToList(ptrRecords), Optional.ToList(srvRecords), Optional.ToList(txtRecords), cnameRecord.Value, soaRecord.Value, Optional.ToList(caaRecords))); }
internal static CnameRecordSetData DeserializeCnameRecordSetData(JsonElement element) { Optional <string> etag = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <IDictionary <string, string> > metadata = default; Optional <long> ttl = default; Optional <string> fqdn = default; Optional <string> provisioningState = default; Optional <WritableSubResource> targetResource = default; Optional <CnameRecord> cnameRecord = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("metadata")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, property1.Value.GetString()); } metadata = dictionary; continue; } if (property0.NameEquals("TTL")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ttl = property0.Value.GetInt64(); continue; } if (property0.NameEquals("fqdn")) { fqdn = property0.Value.GetString(); continue; } if (property0.NameEquals("provisioningState")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("targetResource")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } targetResource = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("CNAMERecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } cnameRecord = CnameRecord.DeserializeCnameRecord(property0.Value); continue; } } continue; } } return(new CnameRecordSetData(id, name, type, systemData, etag.Value, Optional.ToDictionary(metadata), Optional.ToNullable(ttl), fqdn.Value, provisioningState.Value, targetResource, cnameRecord.Value)); }
public SpaStack(Construct scope, string id, SpaStackProps props) : base(scope, id, props) { //s3 bucket var bucket = new Bucket(this, $"{props.ServiceName}-bucket", new BucketProps { WebsiteIndexDocument = "index.html", Versioned = true, BucketName = props.ServiceName, RemovalPolicy = RemovalPolicy.DESTROY }); //cloudfront distribution var cloudFrontOai = new OriginAccessIdentity(this, $"{props.ServiceName}-oai", new OriginAccessIdentityProps { Comment = $"OAI for {props.ServiceName}." }); var cloudfrontDist = new CloudFrontWebDistribution(this, $"{props.ServiceName}-cfd", new CloudFrontWebDistributionProps { ViewerCertificate = ViewerCertificate.FromAcmCertificate( props.CloudFrontCert, new ViewerCertificateOptions { Aliases = new [] { $"{props.SubDomain}.{props.HostedZoneName}" }, SslMethod = SSLMethod.SNI }), OriginConfigs = new ISourceConfiguration[] { new SourceConfiguration { S3OriginSource = new S3OriginConfig { S3BucketSource = bucket, OriginAccessIdentity = cloudFrontOai }, Behaviors = new IBehavior[] { new Behavior { IsDefaultBehavior = true, } } } } }); var cnameRecord = new CnameRecord(this, $"{props.ServiceName}CloudFrontCname", new CnameRecordProps { Zone = HostedZone.FromHostedZoneAttributes(this, "HostedZone", new HostedZoneAttributes { ZoneName = props.HostedZoneName, HostedZoneId = props.HostedZoneId }), RecordName = props.SubDomain, DomainName = cloudfrontDist.DistributionDomainName }); var cloudfrontS3Access = new PolicyStatement(); cloudfrontS3Access.AddActions("s3:GetBucket*", "s3:GetObject*", "s3:List*"); cloudfrontS3Access.AddResources(bucket.BucketArn); cloudfrontS3Access.AddResources($"{bucket.BucketArn}/*"); cloudfrontS3Access.AddCanonicalUserPrincipal(cloudFrontOai.CloudFrontOriginAccessIdentityS3CanonicalUserId); bucket.AddToResourcePolicy(cloudfrontS3Access); //codebuild project var codeBuildProject = new Project(this, $"{props.ServiceName}-codeBuild-project", new ProjectProps { Vpc = props.Vpc, ProjectName = props.ServiceName, Environment = new BuildEnvironment { BuildImage = LinuxBuildImage.STANDARD_4_0, }, Source = Source.GitHub(props.GitHubSourceProps), BuildSpec = BuildSpec.FromSourceFilename(props.BuildSpecFile), EnvironmentVariables = new Dictionary <string, IBuildEnvironmentVariable> { { "SPA_DIRECTORY", new BuildEnvironmentVariable { Value = props.SpaDirectory } }, { "S3_BUCKET", new BuildEnvironmentVariable { Value = bucket.BucketName } }, { "CLOUDFRONT_ID", new BuildEnvironmentVariable { Value = cloudfrontDist.DistributionId } }, { "API_URL", new BuildEnvironmentVariable { Value = props.ApiUrl } } } }); // iam policy to push your build to S3 codeBuildProject.AddToRolePolicy( new PolicyStatement(new PolicyStatementProps { Effect = Effect.ALLOW, Resources = new[] { bucket.BucketArn, $"{bucket.BucketArn}/*" }, Actions = new[] { "s3:GetBucket*", "s3:List*", "s3:GetObject*", "s3:DeleteObject", "s3:PutObject" } })); codeBuildProject.AddToRolePolicy( new PolicyStatement(new PolicyStatementProps { Effect = Effect.ALLOW, Resources = new [] { "*" }, Actions = new [] { "cloudfront:CreateInvalidation", "cloudfront:GetDistribution*", "cloudfront:GetInvalidation", "cloudfront:ListInvalidations", "cloudfront:ListDistributions" } })); //codepipeline? }
internal CdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) { var stackProps = ReportStackProps.ParseOrDefault(props); var dframeWorkerLogGroup = "MagicOnionBenchWorkerLogGroup"; var dframeMasterLogGroup = "MagicOnionBenchMasterLogGroup"; var benchNetwork = stackProps.GetBenchNetwork(); var recreateMagicOnionTrigger = stackProps.GetBenchmarkServerBinariesHash(); // s3 var s3 = new Bucket(this, "Bucket", new BucketProps { AutoDeleteObjects = true, RemovalPolicy = RemovalPolicy.DESTROY, AccessControl = BucketAccessControl.PRIVATE, }); var lifecycleRule = new LifecycleRule { Enabled = true, Prefix = "reports/", Expiration = Duration.Days(stackProps.DaysKeepReports), AbortIncompleteMultipartUploadAfter = Duration.Days(1), }; s3.AddLifecycleRule(lifecycleRule); s3.AddToResourcePolicy(new PolicyStatement(new PolicyStatementProps { Sid = "AllowPublicRead", Effect = Effect.ALLOW, Principals = new[] { new AnyPrincipal() }, Actions = new[] { "s3:GetObject*" }, Resources = new[] { $"{s3.BucketArn}/html/*" }, })); s3.AddToResourcePolicy(new PolicyStatement(new PolicyStatementProps { Sid = "AllowAwsAccountAccess", Effect = Effect.ALLOW, Principals = new[] { new AccountRootPrincipal() }, Actions = new[] { "s3:*" }, Resources = new[] { $"{s3.BucketArn}/*" }, })); // s3 deploy var masterDllDeployment = new BucketDeployment(this, "DeployMasterDll", new BucketDeploymentProps { DestinationBucket = s3, Sources = new[] { Source.Asset(Path.Combine(Directory.GetCurrentDirectory(), $"out/linux/server")) }, DestinationKeyPrefix = $"assembly/linux/server" }); var userdataDeployment = new BucketDeployment(this, "UserData", new BucketDeploymentProps { DestinationBucket = s3, Sources = new[] { Source.Asset(Path.Combine(Directory.GetCurrentDirectory(), "userdata/")) }, DestinationKeyPrefix = "userdata/" }); // docker deploy var dockerImage = new DockerImageAsset(this, "dframeWorkerImage", new DockerImageAssetProps { Directory = Path.Combine(Directory.GetCurrentDirectory(), "app"), File = "ConsoleAppEcs/Dockerfile.Ecs", }); var dframeImage = ContainerImage.FromDockerImageAsset(dockerImage); // network var vpc = new Vpc(this, "Vpc", new VpcProps { MaxAzs = 2, NatGateways = 0, SubnetConfiguration = new[] { new SubnetConfiguration { Name = "public", SubnetType = SubnetType.PUBLIC } }, }); var allsubnets = new SubnetSelection { Subnets = vpc.PublicSubnets }; var singleSubnets = new SubnetSelection { Subnets = new[] { vpc.PublicSubnets.First() } }; var sg = new SecurityGroup(this, "MasterSg", new SecurityGroupProps { AllowAllOutbound = true, Vpc = vpc, }); foreach (var subnet in vpc.PublicSubnets) { sg.AddIngressRule(Peer.Ipv4(vpc.VpcCidrBlock), Port.AllTcp(), "VPC", true); } // service discovery var serviceDiscoveryDomain = "local"; var serverMapName = "server"; var dframeMapName = "dframe-master"; var ns = new PrivateDnsNamespace(this, "Namespace", new PrivateDnsNamespaceProps { Vpc = vpc, Name = serviceDiscoveryDomain, }); var serviceDiscoveryServer = ns.CreateService("server", new DnsServiceProps { Name = serverMapName, DnsRecordType = DnsRecordType.A, RoutingPolicy = RoutingPolicy.MULTIVALUE, }); // alb var albDnsName = "benchmark-alb"; var benchToMagicOnionDnsName = benchNetwork.RequireAlb ? $"{benchNetwork.EndpointScheme}://{albDnsName}.{stackProps.AlbDomain.domain}" : $"{benchNetwork.EndpointScheme}://{serverMapName}.{serviceDiscoveryDomain}"; IApplicationTargetGroup grpcTargetGroup = null; IApplicationTargetGroup httpsTargetGroup = null; if (benchNetwork.RequireAlb) { // route53 var hostedZone = HostedZone.FromHostedZoneAttributes(this, "HostedZone", new HostedZoneAttributes { HostedZoneId = stackProps.AlbDomain.zoneId, ZoneName = stackProps.AlbDomain.domain, }); // acm var certificate = new DnsValidatedCertificate(this, "certificate", new DnsValidatedCertificateProps { DomainName = $"{albDnsName}.{hostedZone.ZoneName}", HostedZone = hostedZone, }); // alb var lb = new ApplicationLoadBalancer(this, "LB", new ApplicationLoadBalancerProps { Vpc = vpc, VpcSubnets = allsubnets, SecurityGroup = new SecurityGroup(this, "AlbSg", new SecurityGroupProps { AllowAllOutbound = true, Vpc = vpc, }), InternetFacing = false, Http2Enabled = true, }); grpcTargetGroup = AddGrpcTargetGroup(benchNetwork, vpc, certificate, lb); httpsTargetGroup = AddHttpsTargetGroup(benchNetwork, vpc, certificate, lb); // Dns Record _ = new CnameRecord(this, "alb-alias-record", new CnameRecordProps { RecordName = $"{albDnsName}.{stackProps.AlbDomain.domain}", Ttl = Duration.Seconds(60), Zone = hostedZone, DomainName = lb.LoadBalancerDnsName, }); } // iam var iamEc2MagicOnionRole = GetIamEc2MagicOnionRole(s3, serviceDiscoveryServer); var iamEcsTaskExecuteRole = GetIamEcsTaskExecuteRole(new[] { dframeWorkerLogGroup, dframeMasterLogGroup }); var iamDFrameTaskDefRole = GetIamEcsDframeTaskDefRole(s3); var iamWorkerTaskDefRole = GetIamEcsWorkerTaskDefRole(s3); // secrets var ddToken = stackProps.UseEc2DatadogAgentProfiler || stackProps.UseFargateDatadogAgentProfiler ? Amazon.CDK.AWS.SecretsManager.Secret.FromSecretNameV2(this, "dd-token", "magiconion-benchmark-datadog-token") : null; // MagicOnion var asg = new AutoScalingGroup(this, "MagicOnionAsg", new AutoScalingGroupProps { // Monitoring is default DETAILED. SpotPrice = "1.0", // 0.0096 for spot price average for m3.medium Vpc = vpc, SecurityGroup = sg, VpcSubnets = singleSubnets, InstanceType = stackProps.MagicOnionInstanceType, DesiredCapacity = 1, MaxCapacity = 1, MinCapacity = 0, AssociatePublicIpAddress = true, MachineImage = new AmazonLinuxImage(new AmazonLinuxImageProps { CpuType = AmazonLinuxCpuType.X86_64, Generation = AmazonLinuxGeneration.AMAZON_LINUX_2, Storage = AmazonLinuxStorage.GENERAL_PURPOSE, Virtualization = AmazonLinuxVirt.HVM, }), AllowAllOutbound = true, GroupMetrics = new[] { GroupMetrics.All() }, Role = iamEc2MagicOnionRole, UpdatePolicy = UpdatePolicy.ReplacingUpdate(), Signals = Signals.WaitForCount(1, new SignalsOptions { Timeout = Duration.Minutes(10), }), }); asg.AddSecretsReadGrant(ddToken, () => stackProps.UseEc2DatadogAgentProfiler); var userdata = GetUserData(recreateMagicOnionTrigger, s3.BucketName, stackProps.BenchmarkBinaryNames, serviceDiscoveryServer.ServiceId, stackProps.UseEc2CloudWatchAgentProfiler, stackProps.UseEc2DatadogAgentProfiler); asg.AddUserData(userdata); asg.UserData.AddSignalOnExitCommand(asg); asg.Node.AddDependency(masterDllDeployment); asg.Node.AddDependency(userdataDeployment); if (stackProps.EnableMagicOnionScaleInCron) { asg.ScaleOnSchedule("ScheduleOut", new BasicScheduledActionProps { DesiredCapacity = 1, MaxCapacity = 1, // AM9:00 (JST+9) on Monday to Wednesday Schedule = Schedule.Expression("0 0 * 1-3 *"), }); asg.ScaleOnSchedule("ScheduleIn", new BasicScheduledActionProps { DesiredCapacity = 0, MaxCapacity = 0, // PM9:00 (JST+9) on Everyday Schedule = Schedule.Expression("0 12 * 1-7 *"), }); } if (benchNetwork.RequireAlb) { asg.AttachToApplicationTargetGroup(grpcTargetGroup); asg.AttachToApplicationTargetGroup(httpsTargetGroup); } // ECS var cluster = new Cluster(this, "WorkerCluster", new ClusterProps { Vpc = vpc, }); cluster.Node.AddDependency(asg); // wait until asg is up // dframe-worker var dframeWorkerContainerName = "worker"; var dframeWorkerTaskDef = new FargateTaskDefinition(this, "DFrameWorkerTaskDef", new FargateTaskDefinitionProps { ExecutionRole = iamEcsTaskExecuteRole, TaskRole = iamWorkerTaskDefRole, Cpu = stackProps.WorkerFargate.CpuSize, MemoryLimitMiB = stackProps.WorkerFargate.MemorySize, }); dframeWorkerTaskDef.AddContainer(dframeWorkerContainerName, new ContainerDefinitionOptions { Image = dframeImage, Command = new[] { "--worker-flag" }, Environment = new Dictionary <string, string> { { "DFRAME_MASTER_CONNECT_TO_HOST", $"{dframeMapName}.{serviceDiscoveryDomain}" }, { "DFRAME_MASTER_CONNECT_TO_PORT", "12345" }, { "BENCH_SERVER_HOST", benchToMagicOnionDnsName }, { "BENCH_REPORTID", stackProps.ReportId }, { "BENCH_S3BUCKET", s3.BucketName }, }, Logging = LogDriver.AwsLogs(new AwsLogDriverProps { LogGroup = new LogGroup(this, "WorkerLogGroup", new LogGroupProps { LogGroupName = dframeWorkerLogGroup, RemovalPolicy = RemovalPolicy.DESTROY, Retention = RetentionDays.TWO_WEEKS, }), StreamPrefix = dframeWorkerLogGroup, }), }); dframeWorkerTaskDef.AddDatadogContainer($"{dframeWorkerContainerName}-datadog", ddToken, () => stackProps.UseFargateDatadogAgentProfiler); var dframeWorkerService = new FargateService(this, "DFrameWorkerService", new FargateServiceProps { ServiceName = "DFrameWorkerService", DesiredCount = 0, Cluster = cluster, TaskDefinition = dframeWorkerTaskDef, VpcSubnets = singleSubnets, SecurityGroups = new[] { sg }, PlatformVersion = FargatePlatformVersion.VERSION1_4, MinHealthyPercent = 0, AssignPublicIp = true, }); // dframe-master var dframeMasterTaskDef = new FargateTaskDefinition(this, "DFrameMasterTaskDef", new FargateTaskDefinitionProps { ExecutionRole = iamEcsTaskExecuteRole, TaskRole = iamDFrameTaskDefRole, Cpu = stackProps.MasterFargate.CpuSize, MemoryLimitMiB = stackProps.MasterFargate.MemorySize, }); dframeMasterTaskDef.AddContainer("dframe", new ContainerDefinitionOptions { Image = dframeImage, Environment = new Dictionary <string, string> { { "DFRAME_CLUSTER_NAME", cluster.ClusterName }, { "DFRAME_MASTER_SERVICE_NAME", "DFrameMasterService" }, { "DFRAME_WORKER_CONTAINER_NAME", dframeWorkerContainerName }, { "DFRAME_WORKER_SERVICE_NAME", dframeWorkerService.ServiceName }, { "DFRAME_WORKER_TASK_NAME", Fn.Select(1, Fn.Split("/", dframeWorkerTaskDef.TaskDefinitionArn)) }, { "DFRAME_WORKER_IMAGE", dockerImage.ImageUri }, { "BENCH_REPORTID", stackProps.ReportId }, { "BENCH_S3BUCKET", s3.BucketName }, }, Logging = LogDriver.AwsLogs(new AwsLogDriverProps { LogGroup = new LogGroup(this, "MasterLogGroup", new LogGroupProps { LogGroupName = dframeMasterLogGroup, RemovalPolicy = RemovalPolicy.DESTROY, Retention = RetentionDays.TWO_WEEKS, }), StreamPrefix = dframeMasterLogGroup, }), }); dframeMasterTaskDef.AddDatadogContainer($"dframe-datadog", ddToken, () => stackProps.UseFargateDatadogAgentProfiler); var dframeMasterService = new FargateService(this, "DFrameMasterService", new FargateServiceProps { ServiceName = "DFrameMasterService", DesiredCount = 1, Cluster = cluster, TaskDefinition = dframeMasterTaskDef, VpcSubnets = singleSubnets, SecurityGroups = new[] { sg }, PlatformVersion = FargatePlatformVersion.VERSION1_4, MinHealthyPercent = 0, AssignPublicIp = true, }); dframeMasterService.EnableCloudMap(new CloudMapOptions { CloudMapNamespace = ns, Name = dframeMapName, DnsRecordType = DnsRecordType.A, DnsTtl = Duration.Seconds(300), }); // output new CfnOutput(this, "ReportUrl", new CfnOutputProps { Value = $"https://{s3.BucketRegionalDomainName}/html/{stackProps.ReportId}/index.html" }); new CfnOutput(this, "EndPointStyle", new CfnOutputProps { Value = stackProps.BenchmarkEndpoint.ToString() }); new CfnOutput(this, "AsgName", new CfnOutputProps { Value = asg.AutoScalingGroupName }); new CfnOutput(this, "EcsClusterName", new CfnOutputProps { Value = cluster.ClusterName }); new CfnOutput(this, "DFrameWorkerEcsTaskdefImage", new CfnOutputProps { Value = dockerImage.ImageUri }); }
public override void ExecuteCmdlet() { DnsRecordBase result = null; switch (this.ParameterSetName) { case ParameterSetA: { result = new ARecord { Ipv4Address = this.Ipv4Address }; break; } case ParameterSetAaaa: { result = new AaaaRecord { Ipv6Address = this.Ipv6Address }; break; } case ParameterSetMx: { result = new MxRecord { Preference = this.Preference, Exchange = this.Exchange }; break; } case ParameterSetNs: { result = new NsRecord { Nsdname = this.Nsdname }; break; } case ParameterSetSrv: { result = new SrvRecord { Priority = this.Priority, Port = this.Port, Target = this.Target, Weight = this.Weight }; break; } case ParameterSetTxt: { result = new TxtRecord { Value = this.Value }; break; } case ParameterSetCName: { result = new CnameRecord { Cname = this.Cname }; break; } case ParameterSetPtr: { result = new PtrRecord {Ptrdname = this.Ptrdname}; break; } default: { throw new PSArgumentException(string.Format(ProjectResources.Error_UnknownParameterSetName, this.ParameterSetName)); } } WriteObject(result); }