/// <summary>
                                      /// Returns the best suitable package binaries for this application - packages that match the specified OS
                                      /// </summary>
                                      /// <param name="os">OS to match</param>
                                      /// <returns>Best suitable packages</returns>
                                      public IEnumerable <AppPackage> MatchPackageBinaries(string os)
                                      {
                                          var platform = Metabank.GetOSPlatformName(os);

                                          var result = new List <AppPackage>();

                                          foreach (var ap in Packages)
                                          {
                                              var match = Metabank.CatalogBin.Packages.Where(pi => Metabank.INVSTRCMP.Equals(pi.Name, ap.Name) &&
                                                                                             Metabank.INVSTRCMP.Equals(pi.Version, ap.Version) &&
                                                                                             (pi.IsAnyPlatform || Metabank.INVSTRCMP.Equals(pi.Platform, platform)) &&
                                                                                             (pi.IsAnyOS || Metabank.INVSTRCMP.Equals(pi.OS, os))
                                                                                             ).OrderBy(pi => - pi.Specificity).FirstOrDefault();//highest first
                                              if (match == null)
                                              {
                                                  throw new MetabaseException(StringConsts.METABASE_APP_DOES_NOT_HAVE_MATCHING_BIN_ERROR.Args(Name, ap.Name, ap.Version, os));
                                              }

                                              result.Add(new AppPackage(ap, match));
                                          }
                                          return(result);
                                      }
Esempio n. 2
0
                                      /// <summary>
                                      /// Gets host by name
                                      /// </summary>
                                      public SectionHost GetHost(string name)
                                      {
                                          string CACHE_KEY = ("ZN.h" + Path + name).ToLowerInvariant();
                                          //1. Try to get from cache
                                          var result = Metabank.cacheGet(REG_CATALOG, CACHE_KEY) as SectionHost;

                                          if (result != null)
                                          {
                                              return(result);
                                          }

                                          var rdir  = "{0}{1}".Args(name, RegCatalog.HST_EXT);
                                          var rpath = Metabank.JoinPaths(Path, rdir);

                                          result =
                                              Metabank.fsAccess("Zone[{0}].GetHost({1})".Args(m_Name, name), rpath,
                                                                (session, dir) => new SectionHost(this, name, rpath, session)
                                                                );


                                          Metabank.cachePut(REG_CATALOG, CACHE_KEY, result);
                                          return(result);
                                      }
Esempio n. 3
0
                                      /// <summary>
                                      /// Gets the information for the best suitable binary packages on this host for the named app
                                      /// </summary>
                                      /// <param name="appName">Metabase application name which should resolve in App catalog</param>
                                      public IEnumerable <SectionApplication.AppPackage> GetAppPackages(string appName)
                                      {
                                          const string CACHE_TABLE = "AppPackages";
                                          string       CACHE_KEY   = (this.RegionPath + "." + appName).ToLowerInvariant();
                                          //1. Try to get from cache
                                          var result = Metabank.cacheGet(CACHE_TABLE, CACHE_KEY) as IEnumerable <SectionApplication.AppPackage>;

                                          if (result != null)
                                          {
                                              return(result);
                                          }

                                          try
                                          {
                                              result = this.calculateAppPackages(appName);
                                          }
                                          catch (Exception error)
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_APP_PACKAGES_ERROR.Args(appName, RegionPath, error.ToMessageWithType()), error);
                                          }

                                          Metabank.cachePut(CACHE_TABLE, CACHE_KEY, result);
                                          return(result);
                                      }
Esempio n. 4
0
                                      //20150403 DKh added support for include pragmas
                                      private ConfigSectionNode calculateEffectiveAppConfig(string appName)
                                      {
                                          var pragmasDisabled = Metabank.RootConfig.AttrByName(Metabank.CONFIG_APP_CONFIG_INCLUDE_PRAGMAS_DISABLED_ATTR).ValueAsBool(false);
                                          var includePragma   = Metabank.RootConfig.AttrByName(Metabank.CONFIG_APP_CONFIG_INCLUDE_PRAGMA_ATTR).Value;


                                          var conf = new MemoryConfiguration();

                                          conf.CreateFromNode(Metabank.RootAppConfig);
                                          conf.Application = this.Metabank.SkyApp;

                                          var result = conf.Root;

                                          if (!pragmasDisabled)
                                          {
                                              result.ProcessAllExistingIncludes("root", includePragma);
                                          }

                                          var derivation = new List <configLevel>();

                                          #region build derivation chain --------------------------------------------------------------------------
                                          //Role level
                                          var role = this.Role;

                                          if (!role.AppNames.Any(an => INVSTRCMP.Equals(an, appName)))
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_HOST_ROLE_APP_MISMATCH_ERROR.Args(appName, RoleName));
                                          }

                                          derivation.Add(new configLevel(role, role.AnyAppConfig));

                                          //App level
                                          var app = Metabank.CatalogApp.Applications[appName];
                                          if (app == null)
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_BAD_HOST_APP_ERROR.Args(appName));
                                          }

                                          derivation.Add(new configLevel(app, app.AnyAppConfig));

                                          //Regional level
                                          var parents = this.ParentSectionsOnPath;
                                          foreach (var item in parents)
                                          {
                                              derivation.Add(new configLevel(item, item.AnyAppConfig));
                                              derivation.Add(new configLevel(item, item.GetAppConfig(appName)));
                                          }

                                          //This Level
                                          derivation.Add(new configLevel(this, this.AnyAppConfig));
                                          derivation.Add(new configLevel(this, this.GetAppConfig(appName)));
                                          #endregion

                                          foreach (var clevel in derivation.Where(cl => cl.Node != null))
                                          {
                                              if (!pragmasDisabled)
                                              {
                                                  ((ConfigSectionNode)clevel.Node).ProcessAllExistingIncludes(clevel.From.ToString(), includePragma);
                                              }

                                              try
                                              {
                                                  result.OverrideBy(clevel.Node);
                                              }
                                              catch (Exception error)
                                              {
                                                  throw new MetabaseException(StringConsts.METABASE_EFFECTIVE_APP_CONFIG_OVERRIDE_ERROR.Args(clevel.From.ToString(), error.ToMessageWithType()), error);
                                              }
                                          }

                                          //OS Include
                                          var include = result[CONFIG_OS_APP_CONFIG_INCLUDE_SECTION];
                                          if (include.Exists)
                                          {
                                              var osInclude = Metabank.GetOSConfNode(this.OS)[CONFIG_APP_CONFIG_SECTION] as ConfigSectionNode;
                                              if (osInclude.Exists)
                                              {
                                                  include.Configuration.Include(include, osInclude);
                                              }
                                          }

                                          result.ResetModified();
                                          return(result);
                                      }
Esempio n. 5
0
                                      protected Section(Catalog catalog, string name, string path, FileSystemSession session)
                                      {
                                          if (name.IsNullOrWhiteSpace() || catalog == null || path.IsNullOrWhiteSpace())
                                          {
                                              throw new MetabaseException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".ctor(catalog|name|path==null|empty");
                                          }
                                          Catalog  = catalog;
                                          Metabank = catalog.Metabank;
                                          m_Name   = name;
                                          Path     = Metabank.JoinPaths("", path);//ensure root path symbol i.e.

                                          m_LevelConfig = Metabank.getConfigFromFile(session, Metabank.JoinPaths(path, Metabank.CONFIG_SECTION_LEVEL_FILE)).Root;

                                          if (!m_LevelConfig.IsSameName(RootNodeName))
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_METADATA_CTOR_1_ERROR.Args(GetType().Name, RootNodeName, m_LevelConfig.Name));
                                          }

                                          var cn = m_LevelConfig.AttrByName(Metabank.CONFIG_NAME_ATTR);

                                          if (!cn.Exists || !m_LevelConfig.IsSameNameAttr(name))
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_METADATA_CTOR_2_ERROR.Args(GetType().Name, name, cn.ValueAsString(SysConsts.UNKNOWN_ENTITY)));
                                          }

                                          if (!name.IsValidName())
                                          {
                                              throw new MetabaseException(StringConsts.METABASE_METADATA_CTOR_3_ERROR.Args(GetType().Name, name, path));
                                          }

                                          Metabank.includeCommonConfig(m_LevelConfig);
                                          m_LevelConfig.ResetModified();
                                      }
Esempio n. 6
0
 protected SystemCatalog(Metabank bank, string name) : base(bank, name)
 {
 }
Esempio n. 7
0
 protected SectionWithAnyAppConfig(Catalog catalog, string name, string path, FileSystemSession session) : base(catalog, name, path, session)
 {
     m_AnyAppConfig = Metabank.getConfigFromFile(session, Metabank.JoinPaths(path, Metabank.CONFIG_SECTION_LEVEL_ANY_APP_FILE), require: false).Root;
 }
Esempio n. 8
0
 protected UserCatalog(Metabank bank, string name) : base(bank, name)
 {
 }
Esempio n. 9
0
 internal BinCatalog(Metabank bank) : base(bank, BIN_CATALOG)
 {
 }
Esempio n. 10
0
                                      private void validateRouting(ValidationContext ctx)
                                      {
                                          var routing = this.LevelConfig[CONFIG_NETWORK_ROUTING_SECTION];

                                          if (!routing.Exists)
                                          {
                                              return;
                                          }
                                          var routeNodes = routing.Children.Where(n => n.IsSameName(CONFIG_NETWORK_ROUTING_ROUTE_SECTION));

                                          foreach (var rnode in routeNodes)
                                          {
                                              foreach (var anode in rnode.Attributes)
                                              {
                                                  if (!anode.IsSameName(CONFIG_NETWORK_ROUTING_NETWORK_ATTR) &&
                                                      !anode.IsSameName(CONFIG_NETWORK_ROUTING_SERVICE_ATTR) &&
                                                      !anode.IsSameName(CONFIG_NETWORK_ROUTING_BINDING_ATTR) &&
                                                      !anode.IsSameName(CONFIG_NETWORK_ROUTING_FROM_ATTR) &&
                                                      !anode.IsSameName(CONFIG_NETWORK_ROUTING_TO_ADDRESS_ATTR) &&
                                                      !anode.IsSameName(CONFIG_NETWORK_ROUTING_TO_PORT_ATTR) &&
                                                      !anode.IsSameName(CONFIG_NETWORK_ROUTING_TO_GROUP_ATTR)
                                                      )
                                                  {
                                                      ctx.Output.Add(new MetabaseValidationMsg(MetabaseValidationMessageType.Warning, Catalog, this,
                                                                                               StringConsts.METABASE_NETWORK_REGION_ROUTING_ATTR_UNRECOGNIZED_WARNING.Args(RegionPath, anode.Name)));
                                                  }
                                              }



                                              var net     = rnode.AttrByName(CONFIG_NETWORK_ROUTING_NETWORK_ATTR).Value;
                                              var svc     = rnode.AttrByName(CONFIG_NETWORK_ROUTING_SERVICE_ATTR).Value;
                                              var binding = rnode.AttrByName(CONFIG_NETWORK_ROUTING_BINDING_ATTR).Value;
                                              var from    = rnode.AttrByName(CONFIG_NETWORK_ROUTING_FROM_ATTR).Value;

                                              var toaddr  = rnode.AttrByName(CONFIG_NETWORK_ROUTING_TO_ADDRESS_ATTR).Value;
                                              var toport  = rnode.AttrByName(CONFIG_NETWORK_ROUTING_TO_PORT_ATTR).Value;
                                              var togroup = rnode.AttrByName(CONFIG_NETWORK_ROUTING_TO_GROUP_ATTR).Value;

                                              if (toaddr.IsNullOrWhiteSpace() &&
                                                  toport.IsNullOrWhiteSpace() &&
                                                  togroup.IsNullOrWhiteSpace())
                                              {
                                                  ctx.Output.Add(new MetabaseValidationMsg(MetabaseValidationMessageType.Error, Catalog, this, StringConsts.METABASE_NETWORK_REGION_ROUTING_EMPTY_ROUTE_ASSIGNMENT_ERROR.Args(RegionPath)));
                                              }

                                              if (net.IsNotNullOrEmpty())
                                              {
                                                  try
                                                  {
                                                      var netNode = Metabank.GetNetworkConfNode(net);
                                                  }
                                                  catch (Exception error)
                                                  {
                                                      ctx.Output.Add(new MetabaseValidationMsg(MetabaseValidationMessageType.Error, Catalog, this, error.ToMessageWithType()));
                                                  }

                                                  if (svc.IsNotNullOrWhiteSpace())
                                                  {
                                                      try
                                                      {
                                                          var svcNode = Metabank.GetNetworkSvcConfNode(net, svc);
                                                      }
                                                      catch (Exception error)
                                                      {
                                                          ctx.Output.Add(new MetabaseValidationMsg(MetabaseValidationMessageType.Error, Catalog, this, error.ToMessageWithType()));
                                                      }

                                                      if (binding.IsNotNullOrWhiteSpace())
                                                      {
                                                          try
                                                          {
                                                              var svcNode = Metabank.GetNetworkSvcBindingConfNode(net, svc, binding);
                                                          }
                                                          catch (Exception error)
                                                          {
                                                              ctx.Output.Add(new MetabaseValidationMsg(MetabaseValidationMessageType.Error, Catalog, this, error.ToMessageWithType()));
                                                          }
                                                      }
                                                  }
                                              }

                                              if (from.IsNotNullOrWhiteSpace())
                                              {
                                                  var reg = Metabank.CatalogReg[from];
                                                  if (reg == null)
                                                  {
                                                      ctx.Output.Add(new MetabaseValidationMsg(MetabaseValidationMessageType.Error, Catalog, this, StringConsts.METABASE_NETWORK_REGION_ROUTING_FROM_PATH_ERROR.Args(RegionPath, from)));
                                                  }
                                              }
                                          }
                                      }
Esempio n. 11
0
 internal AppCatalog(Metabank bank) : base(bank, APP_CATALOG)
 {
 }
Esempio n. 12
0
 internal RegCatalog(Metabank bank) : base(bank, REG_CATALOG)
 {
 }