예제 #1
0
 /// <summary>
 /// Add the specified runtime to a role, checking that the runtime and version are currently available int he cloud
 /// </summary>
 /// <param name="paths">service path info</param>
 /// <param name="roleName">Name of the role to change</param>
 /// <param name="runtimeType">The runtime identifier</param>
 /// <param name="runtimeVersion">The runtime version</param>
 /// <param name="manifest">Location fo the manifest file, default is the cloud manifest</param>
 public void AddRoleRuntime(ServicePathInfo paths, string roleName, string runtimeType, string runtimeVersion, string manifest = null)
 {
     if (this.Components.RoleExists(roleName))
     {
         CloudRuntimeCollection collection;
         CloudRuntimeCollection.CreateCloudRuntimeCollection(Location.NorthCentralUS, out collection, manifest);
         CloudRuntime        desiredRuntime = CloudRuntime.CreateCloudRuntime(runtimeType, runtimeVersion, roleName, Path.Combine(paths.RootPath, roleName));
         CloudRuntimePackage foundPackage;
         if (collection.TryFindMatch(desiredRuntime, out foundPackage))
         {
             WorkerRole worker = (this.Components.Definition.WorkerRole == null ? null :
                                  this.Components.Definition.WorkerRole.FirstOrDefault <WorkerRole>(r => string.Equals(r.name, roleName,
                                                                                                                       StringComparison.OrdinalIgnoreCase)));
             WebRole web = (this.Components.Definition.WebRole == null ? null :
                            this.Components.Definition.WebRole.FirstOrDefault <WebRole>(r => string.Equals(r.name, roleName,
                                                                                                           StringComparison.OrdinalIgnoreCase)));
             if (worker != null)
             {
                 desiredRuntime.ApplyRuntime(foundPackage, worker);
             }
             else if (web != null)
             {
                 desiredRuntime.ApplyRuntime(foundPackage, web);
             }
         }
     }
 }
예제 #2
0
 private void ConfigureNewService(ServiceComponents components, ServicePathInfo paths, string serviceName)
 {
     Components.Definition.name         = serviceName;
     Components.CloudConfig.serviceName = serviceName;
     Components.LocalConfig.serviceName = serviceName;
     Components.Save(paths);
 }
예제 #3
0
        /// <summary>
        /// Retrieve currently available cloud runtimes
        /// </summary>
        /// <param name="paths">service path info</param>
        /// <param name="manifest">The manifest to use to get current runtime info - default is the cloud manifest</param>
        /// <returns></returns>
        public CloudRuntimeCollection GetCloudRuntimes(ServicePathInfo paths, string manifest)
        {
            CloudRuntimeCollection collection;

            CloudRuntimeCollection.CreateCloudRuntimeCollection(Location.NorthCentralUS, out collection, manifest);
            return(collection);
        }
예제 #4
0
        public void ChangeServiceName(string newName, ServicePathInfo paths)
        {
            Validate.ValidateDnsName(newName, "service name");

            Components.Definition.name         = newName;
            Components.CloudConfig.serviceName = newName;
            Components.LocalConfig.serviceName = newName;
            Components.Save(paths);
        }
예제 #5
0
        public void Save(ServicePathInfo paths)
        {
            if (paths == null) throw new ArgumentNullException("paths");
            // Validate directory exists and it's valid

            General.SerializeXmlFile<ServiceDefinition>(Definition, paths.Definition);
            General.SerializeXmlFile<ServiceConfiguration>(CloudConfig, paths.CloudConfiguration);
            General.SerializeXmlFile<ServiceConfiguration>(LocalConfig, paths.LocalConfiguration);
            Settings.Save(paths.Settings);
        }
예제 #6
0
        private void LoadComponents(ServicePathInfo paths)
        {
            Validate.ValidateNullArgument(paths, string.Format(Resources.NullObjectMessage, "paths"));
            Validate.ValidateFileFull(paths.CloudConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.LocalConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.Definition, Resources.ServiceDefinition);
            Validate.ValidateFileFull(paths.Settings, Resources.ServiceSettings);

            Definition = General.DeserializeXmlFile<ServiceDefinition>(paths.Definition);
            CloudConfig = General.DeserializeXmlFile<ServiceConfiguration>(paths.CloudConfiguration);
            LocalConfig = General.DeserializeXmlFile<ServiceConfiguration>(paths.LocalConfiguration);
            Settings = ServiceSettings.Load(paths.Settings);
        }
예제 #7
0
        private void LoadComponents(ServicePathInfo paths)
        {
            Validate.ValidateNullArgument(paths, string.Format(Resources.NullObjectMessage, "paths"));
            Validate.ValidateFileFull(paths.CloudConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.LocalConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.Definition, Resources.ServiceDefinition);
            Validate.ValidateFileFull(paths.Settings, Resources.ServiceSettings);

            Definition  = General.DeserializeXmlFile <ServiceDefinition>(paths.Definition);
            CloudConfig = General.DeserializeXmlFile <ServiceConfiguration>(paths.CloudConfiguration);
            LocalConfig = General.DeserializeXmlFile <ServiceConfiguration>(paths.LocalConfiguration);
            Settings    = ServiceSettings.Load(paths.Settings);
        }
 public void ServicePathInfoTestNullRootPathFail()
 {
     try
     {
         ServicePathInfo paths = new ServicePathInfo(null);
         Assert.Fail("No exception was thrown");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(ex is ArgumentException);
         Assert.AreEqual<string>(string.Format(Resources.InvalidOrEmptyArgumentMessage, "service root"), ex.Message);
     }
 }
예제 #9
0
        public void Save(ServicePathInfo paths)
        {
            if (paths == null)
            {
                throw new ArgumentNullException("paths");
            }
            // Validate directory exists and it's valid

            General.SerializeXmlFile <ServiceDefinition>(Definition, paths.Definition);
            General.SerializeXmlFile <ServiceConfiguration>(CloudConfig, paths.CloudConfiguration);
            General.SerializeXmlFile <ServiceConfiguration>(LocalConfig, paths.LocalConfiguration);
            Settings.Save(paths.Settings);
        }
        public void SetAzureServiceProjectTestsLocationInvalidFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess("MyHome", null, null, null, paths.Settings), string.Format(Resources.InvalidServiceSettingElement, "Location"));
            }
        }
 public void ServicePathInfoTestInvalidRootPathFail()
 {
     foreach (string invalidDirectoryName in Data.InvalidServiceRootName)
     {
         try
         {
             ServicePathInfo paths = new ServicePathInfo(invalidDirectoryName);
             Assert.Fail("No exception was thrown");
         }
         catch (Exception ex)
         {
             Assert.IsTrue(ex is ArgumentException);
             Assert.AreEqual<string>(Resources.InvalidRootNameMessage, ex.Message);
         }
     }
 }
        /// <summary>
        /// Set the runtime properties for a role
        /// </summary>
        /// <param name="definition">The service containing the role</param>
        /// <param name="roleName">The name of the role to change</param>
        /// <param name="path">The path to the service</param>
        /// <param name="version">The version of the runtime to be installed</param>
        /// <param name="overrideUrl">The value of the override url, if the user wants to opt out of the system</param>
        /// <returns>true if the settings were successfully changed</returns>
        public static bool SetRoleRuntime(ServiceDefinition definition, string roleName, ServicePathInfo path, string version = null, string overrideUrl = null)
        {
            bool changed = false;
            Variable[] environment = GetRoleRuntimeEnvironment(definition, roleName);
            if (version != null)
            {
                string filePath = Path.Combine(path.RootPath, roleName, "package.json");
                File.WriteAllText(filePath, string.Format(TestResources.ValidPackageJson, "testapp", version));
                changed = true;
            }

            if (overrideUrl != null)
            {
                environment = SetRuntimeEnvironment(environment, Resources.RuntimeOverrideKey, overrideUrl);
                changed = true;
            }

            return changed && ApplyRuntimeChanges(definition, roleName, environment);
        }
예제 #13
0
        public AzureService(string serviceParentDirectory, string name, string scaffoldingPath)
            : this()
        {
            Validate.ValidateDirectoryFull(serviceParentDirectory, Resources.ServiceParentDirectory);
            Validate.ValidateStringIsNullOrEmpty(name, "Name");
            Validate.ValidateFileName(name, string.Format(Resources.InvalidFileName, "Name"));
            Validate.ValidateDnsName(name, "Name");

            string newServicePath = Path.Combine(serviceParentDirectory, name);
            if (Directory.Exists(newServicePath))
            {
                throw new ArgumentException(string.Format(Resources.ServiceAlreadyExistsOnDisk, name, newServicePath));
            }

            SetScaffolding(scaffoldingPath);
            Paths = new ServicePathInfo(newServicePath);
            CreateNewService(Paths.RootPath, name);
            Components = new ServiceComponents(Paths);
            ConfigureNewService(Components, Paths, name);
        }
예제 #14
0
        public AzureService(string serviceParentDirectory, string name, string scaffoldingPath)
            : this()
        {
            Validate.ValidateDirectoryFull(serviceParentDirectory, Resources.ServiceParentDirectory);
            Validate.ValidateStringIsNullOrEmpty(name, "Name");
            Validate.ValidateFileName(name, string.Format(Resources.InvalidFileName, "Name"));
            Validate.ValidateDnsName(name, "Name");

            string newServicePath = Path.Combine(serviceParentDirectory, name);

            if (Directory.Exists(newServicePath))
            {
                throw new ArgumentException(string.Format(Resources.ServiceAlreadyExistsOnDisk, name, newServicePath));
            }

            SetScaffolding(scaffoldingPath);
            Paths = new ServicePathInfo(newServicePath);
            CreateNewService(Paths.RootPath, name);
            Components = new ServiceComponents(Paths);
            ConfigureNewService(Components, Paths, name);
        }
        public void SetAzureServiceProjectTestsLocationValid()
        {
            foreach (KeyValuePair<Location, string> item in Microsoft.WindowsAzure.Management.CloudService.Model.ArgumentConstants.Locations)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    settings.Save(paths.Settings);

                    new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(item.Value, null, null, null, paths.Settings);

                    // Assert location is changed
                    //
                    settings = ServiceSettings.Load(paths.Settings);
                    Assert.AreEqual<string>(item.Value, settings.Location);
                }
            }
        }
예제 #16
0
 /// <summary>
 /// Retrieve currently available cloud runtimes
 /// </summary>
 /// <param name="paths">service path info</param>
 /// <param name="manifest">The manifest to use to get current runtime info - default is the cloud manifest</param>
 /// <returns></returns>
 public CloudRuntimeCollection GetCloudRuntimes(ServicePathInfo paths, string manifest)
 {
     CloudRuntimeCollection collection;
     CloudRuntimeCollection.CreateCloudRuntimeCollection(Location.NorthCentralUS, out collection, manifest);
     return collection;
 }
예제 #17
0
        public void ChangeServiceName(string newName, ServicePathInfo paths)
        {
            Validate.ValidateDnsName(newName, "service name");

            Components.Definition.name = newName;
            Components.CloudConfig.serviceName = newName;
            Components.LocalConfig.serviceName = newName;
            Components.Save(paths);
        }
예제 #18
0
 public void SetRoleInstances(ServicePathInfo paths, string roleName, int instances)
 {
     Components.SetRoleInstances(roleName, instances);
     Components.Save(paths);
 }
예제 #19
0
 public static void AreEqualServicePathInfo(string rootPath, ServicePathInfo actual)
 {
     Assert.AreEqual<string>(rootPath, actual.RootPath);
     Assert.AreEqual<string>(Path.Combine(rootPath, Resources.ServiceDefinitionFileName), actual.Definition);
     Assert.AreEqual<string>(Path.Combine(rootPath, Resources.CloudServiceConfigurationFileName), actual.CloudConfiguration);
     Assert.AreEqual<string>(Path.Combine(rootPath, Resources.LocalServiceConfigurationFileName), actual.LocalConfiguration);
     Assert.AreEqual<string>(Path.Combine(rootPath, Resources.SettingsFileName), actual.Settings);
     Assert.AreEqual<string>(Path.Combine(rootPath, Resources.CloudPackageFileName), actual.CloudPackage);
     Assert.AreEqual<string>(Path.Combine(rootPath, Resources.LocalPackageFileName), actual.LocalPackage);
 }
 public void ServicePathInfoTest()
 {
     ServicePathInfo paths = new ServicePathInfo("MyService");
     AzureAssert.AreEqualServicePathInfo("MyService", paths);
 }
예제 #21
0
 public AzureService(string rootPath, string scaffoldingPath)
 {
     SetScaffolding(scaffoldingPath);
     Paths = new ServicePathInfo(rootPath);
     Components = new ServiceComponents(Paths);
 }
        public void SetAzureServiceProjectTestsSubscriptionEmptyFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, null, string.Empty, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Subscription"));
            }
        }
        public void ServiceComponentsTestSettingsDoesNotExistFail()
        {
            new NewAzureServiceProjectCommand().NewAzureServiceProcess(Directory.GetCurrentDirectory(), serviceName);
            ServicePathInfo paths = new ServicePathInfo(serviceName);

            try
            {
                File.Delete(paths.Settings);
                ServiceComponents components = new ServiceComponents(paths);
                Assert.Fail("No exception was thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is FileNotFoundException);
                Assert.AreEqual<string>(string.Format(Resources.PathDoesNotExistForElement, Resources.ServiceSettings, paths.Settings), ex.Message);
            }
        }
예제 #24
0
 public ServiceComponents(ServicePathInfo paths)
 {
     LoadComponents(paths);
 }
예제 #25
0
 /// <summary>
 /// Sets the role VMSize
 /// </summary>
 /// <param name="paths">The service paths</param>
 /// <param name="roleName">The name of the role to change its vm size</param>
 /// <param name="VMSize">The new role vm size</param>
 public void SetRoleVMSize(ServicePathInfo paths, string roleName, string VMSize)
 {
     Components.SetRoleVMSize(roleName, VMSize);
     Components.Save(paths);
 }
예제 #26
0
 public static void AreEqualServicePathInfo(ServicePathInfo expected, ServicePathInfo actual)
 {
     AreEqualServicePathInfo(expected.CloudConfiguration, expected.CloudPackage, expected.Definition, expected.LocalConfiguration,
         expected.LocalPackage, expected.RootPath, expected.Settings, actual);
 }
예제 #27
0
 public static void AreEqualServicePathInfo(string cloudConfig, string cloudPackage, string def, string localConfig, string localPackage, string root, string settings, ServicePathInfo actual)
 {
     throw new NotImplementedException();
 }
        public void SetAzureServiceProjectTestsStorageTests()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, "companystore", null, paths.Settings);

                // Assert storageAccountName is changed
                //
                settings = ServiceSettings.Load(paths.Settings);
                Assert.AreEqual<string>("companystore", settings.StorageAccountName);
            }
        }
예제 #29
0
 public void SetRoleInstances(ServicePathInfo paths, string roleName, int instances)
 {
     Components.SetRoleInstances(roleName, instances);
     Components.Save(paths);
 }
예제 #30
0
 /// <summary>
 /// Add the specified runtime to a role, checking that the runtime and version are currently available int he cloud
 /// </summary>
 /// <param name="paths">service path info</param>
 /// <param name="roleName">Name of the role to change</param>
 /// <param name="runtimeType">The runtime identifier</param>
 /// <param name="runtimeVersion">The runtime version</param>
 /// <param name="manifest">Location fo the manifest file, default is the cloud manifest</param>
 public void AddRoleRuntime(ServicePathInfo paths, string roleName, string runtimeType, string runtimeVersion, string manifest = null)
 {
     if (this.Components.RoleExists(roleName))
     {
         CloudRuntimeCollection collection;
         CloudRuntimeCollection.CreateCloudRuntimeCollection(Location.NorthCentralUS, out collection, manifest);
         CloudRuntime desiredRuntime = CloudRuntime.CreateCloudRuntime(runtimeType, runtimeVersion, roleName, Path.Combine(paths.RootPath, roleName));
         CloudRuntimePackage foundPackage;
         if (collection.TryFindMatch(desiredRuntime, out foundPackage))
         {
             WorkerRole worker = (this.Components.Definition.WorkerRole == null ? null :
                 this.Components.Definition.WorkerRole.FirstOrDefault<WorkerRole>(r => string.Equals(r.name, roleName,
                     StringComparison.OrdinalIgnoreCase)));
             WebRole web = (this.Components.Definition.WebRole == null ? null :
                 this.Components.Definition.WebRole.FirstOrDefault<WebRole>(r => string.Equals(r.name, roleName,
                     StringComparison.OrdinalIgnoreCase)));
             if (worker != null)
             {
                 desiredRuntime.ApplyRuntime(foundPackage, worker);
             }
             else if (web != null)
             {
                 desiredRuntime.ApplyRuntime(foundPackage, web);
             }
         }
     }
 }
예제 #31
0
        private void LoadComponents(ServicePathInfo paths)
        {
            Validate.ValidateNullArgument(paths, string.Format(Resources.NullObjectMessage, "paths"));
            Validate.ValidateFileFull(paths.CloudConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.LocalConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.Definition, Resources.ServiceDefinition);

            try
            {
                Validate.ValidateFileFull(paths.Settings, Resources.ServiceSettings);
            }
            catch (FileNotFoundException)
            {
                // Try recreating the settings file
                File.WriteAllText(paths.Settings, Resources.SettingsFileEmptyContent);
            }

            Definition = CloudServiceUtilities.DeserializeXmlFile<ServiceDefinition>(paths.Definition);
            CloudConfig = CloudServiceUtilities.DeserializeXmlFile<ServiceConfiguration>(paths.CloudConfiguration);
            LocalConfig = CloudServiceUtilities.DeserializeXmlFile<ServiceConfiguration>(paths.LocalConfiguration);
            Settings = ServiceSettings.Load(paths.Settings);
        }
예제 #32
0
 public AzureService(string rootPath, string scaffoldingPath)
 {
     SetScaffolding(scaffoldingPath);
     Paths      = new ServicePathInfo(rootPath);
     Components = new ServiceComponents(Paths);
 }
예제 #33
0
 public ServiceComponents(ServicePathInfo paths)
 {
     LoadComponents(paths);
 }
예제 #34
0
 private void ConfigureNewService(ServiceComponents components, ServicePathInfo paths, string serviceName)
 {
     Components.Definition.name = serviceName;
     Components.CloudConfig.serviceName = serviceName;
     Components.LocalConfig.serviceName = serviceName;
     Components.Save(paths);
 }
        public void SetAzureServiceProjectTestsSubscriptionValid()
        {
            foreach (string item in Data.ValidSubscriptionName)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    settings.Save(paths.Settings);

                    new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, null, item, paths.Settings);

                    // Assert subscription is changed
                    //
                    settings = ServiceSettings.Load(paths.Settings);
                    Assert.AreEqual<string>(item, settings.Subscription);
                }
            }
        }