protected void ValidateApplicationInstance(ApplicationInstanceContext appInstanceContext) { foreach (IApplicationValidator validator in this.Validators) { validator.Validate(appInstanceContext); } }
public async Task CreateInstanceAsync(string outputFolder, TimeSpan timeout, ApplicationTypeContext validatedApplicationTypeContext = null) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); ImageBuilder.TraceSource.WriteInfo( TraceType, "Starting CreateInstance. ApplicationTypeName:{0}, ApplicationTypeVersion:{1}, ApplicationId:{2}, Timeout:{3}", this.ApplicationTypeName, this.ApplicationTypeVersion, this.ApplicationId, timeoutHelper.GetRemainingTime()); ApplicationInstanceContext appInstanceContext = await base.CreateAndSortInstanceAsync( 1 /*ApplicationInstace version starts at 1*/, nameUri, timeoutHelper, validatedApplicationTypeContext); this.ValidateApplicationInstance(appInstanceContext); if (validatedApplicationTypeContext == null) { timeoutHelper.ThrowIfExpired(); StoreLayoutSpecification clusterManagerOutputSpecification = null; if (outputFolder != null) { clusterManagerOutputSpecification = StoreLayoutSpecification.Create(); clusterManagerOutputSpecification.SetRoot(outputFolder); } await this.UploadInstanceAsync( appInstanceContext.ApplicationInstance, appInstanceContext.ApplicationPackage, appInstanceContext.ServicePackages, StoreLayoutSpecification.Create(), clusterManagerOutputSpecification, true, timeoutHelper); } ImageBuilder.TraceSource.WriteInfo( TraceType, "Completed CreateInstance. ApplicationTypeName:{0}, ApplicationTypeVersion:{1}, ApplicationId:{2}", this.ApplicationTypeName, this.ApplicationTypeVersion, this.ApplicationId); }
public async Task UpgradeInstaceAsync(string outputFolder, TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); ImageBuilder.TraceSource.WriteInfo( TraceType, "Starting UpgradeInstace. ApplicationTypeName:{0}, TargetApplicationTypeVersion:{1}, CurrentApplicationInstance:{2}, ApplicationId:{3}, Timeout:{4}", this.ApplicationTypeName, this.ApplicationTypeVersion, this.currentApplicationInstanceVersion, this.ApplicationId, timeoutHelper.GetRemainingTime()); StoreLayoutSpecification storeLayoutSpecification = StoreLayoutSpecification.Create(); // Read the current ApplicationInstance and ApplicationPackage from the store string currentApplicationInstanceFile = storeLayoutSpecification.GetApplicationInstanceFile(this.ApplicationTypeName, this.ApplicationId, this.currentApplicationInstanceVersion.ToString(CultureInfo.InvariantCulture)); ApplicationInstanceType currentApplicationInstanceType = this.ImageStoreWrapper.GetFromStore <ApplicationInstanceType>(currentApplicationInstanceFile, timeoutHelper.GetRemainingTime()); string currentApplicationPackageFile = storeLayoutSpecification.GetApplicationPackageFile(this.ApplicationTypeName, this.ApplicationId, currentApplicationInstanceType.ApplicationPackageRef.RolloutVersion); ApplicationPackageType currentApplicationPackageType = this.ImageStoreWrapper.GetFromStore <ApplicationPackageType>(currentApplicationPackageFile, timeoutHelper.GetRemainingTime()); // Read the current ServicePackages from the store List <Task <ServicePackageType> > getServicePackageTasks = new List <Task <ServicePackageType> >(); TimeSpan remainingTime = timeoutHelper.GetRemainingTime(); foreach (ApplicationInstanceTypeServicePackageRef servicePackageRef in currentApplicationInstanceType.ServicePackageRef) { string currentServicePackageFile = storeLayoutSpecification.GetServicePackageFile( this.ApplicationTypeName, this.ApplicationId, servicePackageRef.Name, servicePackageRef.RolloutVersion); var getServicePackageTask = this.ImageStoreWrapper.GetFromStoreAsync <ServicePackageType>(currentServicePackageFile, remainingTime); getServicePackageTasks.Add(getServicePackageTask); } await Task.WhenAll(getServicePackageTasks); Collection <ServicePackageType> currentServicePackages = new Collection <ServicePackageType>(); getServicePackageTasks.ForEach(task => currentServicePackages.Add(task.Result)); timeoutHelper.ThrowIfExpired(); ApplicationInstanceContext targetAppInstanceContext = await base.CreateAndSortInstanceAsync( currentApplicationInstanceType.Version + 1, new Uri(currentApplicationPackageType.NameUri), timeoutHelper); // Validate the target ApplicationInstance and ServicePackages this.ValidateApplicationInstance(targetAppInstanceContext); // Update the Rollout version on the target ApplicationInstance this.UpdateTargetApplicationPackage(currentApplicationPackageType, targetAppInstanceContext.ApplicationPackage); targetAppInstanceContext.ApplicationInstance.ApplicationPackageRef.RolloutVersion = targetAppInstanceContext.ApplicationPackage.RolloutVersion; // Update the Rollout version on the target ServicePackages foreach (ServicePackageType targetServicePackage in targetAppInstanceContext.ServicePackages) { ServicePackageType matchingCurrentServicePackageType = currentServicePackages.FirstOrDefault( currentServicePackage => ImageBuilderUtility.Equals(currentServicePackage.Name, targetServicePackage.Name)); this.UpdateTargetServicePackage(matchingCurrentServicePackageType, targetServicePackage); ApplicationInstanceTypeServicePackageRef matchingServicePackageRef = targetAppInstanceContext.ApplicationInstance.ServicePackageRef.First( servicePackageRef => ImageBuilderUtility.Equals(servicePackageRef.Name, targetServicePackage.Name)); matchingServicePackageRef.RolloutVersion = targetServicePackage.RolloutVersion; } StoreLayoutSpecification clusterManagerOutputSpecification = null; if (outputFolder != null) { clusterManagerOutputSpecification = StoreLayoutSpecification.Create(); clusterManagerOutputSpecification.SetRoot(outputFolder); } timeoutHelper.ThrowIfExpired(); // Upload the target ApplicationInstance and ServicePackages to the store // Also, write the target ApplicationInstance and ServicePackages to the CM output folder await this.UploadInstanceAsync( targetAppInstanceContext.ApplicationInstance, targetAppInstanceContext.ApplicationPackage, targetAppInstanceContext.ServicePackages, storeLayoutSpecification, clusterManagerOutputSpecification, false, timeoutHelper); // Write the current ApplicationInstance and ServicePackages to the CM output folder await this.UploadInstanceAsync( currentApplicationInstanceType, currentApplicationPackageType, currentServicePackages, null /* Do not upload to store*/, clusterManagerOutputSpecification, true, timeoutHelper); ImageBuilder.TraceSource.WriteInfo( TraceType, "Completed UpgradeInstace. ApplicationTypeName:{0}, TargetApplicationTypeVersion:{1}, CurrentApplicationInstance:{2}, ApplicationId:{3}", this.ApplicationTypeName, this.ApplicationTypeVersion, this.currentApplicationInstanceVersion, this.ApplicationId); }
public void Validate(ApplicationInstanceContext applicationInstanceContext) { // No instance validation required }
public void Validate(ApplicationInstanceContext applicationInstanceContext) { this.parametersAlreadyApplied = true; ValidateApplicationManifestDiagnostics(applicationInstanceContext.ApplicationPackage.DigestedEnvironment.Diagnostics); }