Esempio n. 1
0
        /// <summary>
        /// テナントにGitを紐づける。
        /// 結果として、作成したすべての<see cref="UserTenantGitMap"/>を返す。
        /// テナントの新規作成時であれば、<paramref name="isCreate"/>をTrueにする。
        /// </summary>
        public async Task <IEnumerable <UserTenantGitMap> > AttachGitToTenantAsync(Tenant tenant, Git git, bool isCreate)
        {
            if (git == null)
            {
                //指定がなければ何もしない
                return(null);
            }

            TenantGitMap map = new TenantGitMap()
            {
                Git = git
            };

            List <UserTenantGitMap> maps = null;

            if (isCreate == false) //テナント新規作成時はIDが0の状態なので、判定しない。ユーザも未参加なので何もしない。
            {
                map.TenantId = tenant.Id;

                //既に紐づいていたら何もしない
                bool exist = await ExistsModelAsync <TenantGitMap>(m => m.TenantId == tenant.Id && m.GitId == git.Id);

                if (exist)
                {
                    return(null);
                }

                maps = new List <UserTenantGitMap>();

                //テナントに紐づいているすべてのユーザを取得
                var userMaps = FindModelAll <UserTenantMap>(m => m.TenantId == tenant.Id);
                foreach (var userMap in userMaps)
                {
                    UserTenantGitMap utgMap = new UserTenantGitMap()
                    {
                        TenantGitMap = map,
                        UserId       = userMap.UserId,
                    };

                    //既に同じGitと紐づいていたら、その認証情報を使いまわす
                    var existMap = GetModelAll <UserTenantGitMap>().Include(m => m.TenantGitMap)
                                   .Where(m => m.UserId == userMap.UserId && m.TenantGitMap.GitId == git.Id).FirstOrDefault();
                    if (existMap != null)
                    {
                        utgMap.GitToken = existMap.GitToken;
                    }
                    AddModel <UserTenantGitMap>(utgMap);
                    maps.Add(utgMap);
                }
            }
            else
            {
                map.Tenant = tenant;
            }

            AddModel <TenantGitMap>(map);
            return(maps);
        }
Esempio n. 2
0
        private int CreateInitialDB()
        {
            // 初期Git情報取得
            Git git = gitRepository.GetGitAll().First(g => g.Name == "GitHub");
            // 初期レジストリ情報取得
            Registry registry = registryRepository.GetRegistryAll().First(r => r.Name == "official-docker-hub");

            // 初期ノードの作成
            string[] nodeNames = deployOptions.GpuNodes.Split(',');
            foreach (string nodeName in nodeNames)
            {
                AddNewRecordForInit(new Node()
                {
                    Name               = nodeName,
                    AccessLevel        = NodeAccessLevel.Public,
                    TensorBoardEnabled = true,
                    NotebookEnabled    = true
                });
            }

            // 初期ストレージの作成
            Storage storage = AddNewRecordForInit(new Storage()
            {
                Name          = ApplicationConst.DefaultFirstStorageName,
                ServerAddress = deployOptions.ObjectStorageNode + ":" + deployOptions.ObjectStoragePort,
                AccessKey     = deployOptions.ObjectStorageAccessKey,
                SecretKey     = deployOptions.ObjectStorageSecretKey,
                NfsServer     = deployOptions.NfsStorage,
                NfsRoot       = deployOptions.NfsPath
            });

            //初期テナント作成
            Tenant tenant = AddNewRecordForInit(new Tenant()
            {
                Name              = ApplicationConst.DefaultFirstTenantName,
                DisplayName       = ApplicationConst.DefaultFirstTenantDisplayName,
                DefaultGit        = git,
                DefaultRegistryId = registry.Id,
                StorageBucket     = ApplicationConst.DefaultFirstTenantName,
                StorageId         = storage.Id
            });
            //GitとTenantの対応付け
            TenantGitMap tenantGitMap = AddNewRecordForInit(new TenantGitMap()
            {
                Tenant = tenant, Git = git
            });
            //RegistryとTenantの対応付け
            TenantRegistryMap tenantRegistryMap = AddNewRecordForInit(new TenantRegistryMap()
            {
                Tenant = tenant, Registry = registry
            });

            //初期ユーザ作成
            User user = AddNewRecordForInit(new User()
            {
                Name          = ApplicationConst.DefaultFirstAdminUserName,
                ServiceType   = AuthServiceType.Local,
                DefaultTenant = tenant,
                Password      = Util.GenerateHash(deployOptions.Password, ApplicationConst.DefaultFirstAdminUserName)
            });

            //初期ユーザの所属登録
            UserTenantMap userTenantMap = AddNewRecordForInit(new UserTenantMap()
            {
                Tenant = tenant, User = user
            });

            AddNewRecordForInit(new UserTenantGitMap()
            {
                User = user, TenantGitMap = tenantGitMap
            });
            AddNewRecordForInit(new UserTenantRegistryMap()
            {
                User = user, TenantRegistryMap = tenantRegistryMap
            });

            // ロール情報取得
            Role researcherRole = roleRepository.GetCommonTenantRolesAsync().Result.First(r => r.Name == "researchers");
            Role managerRole    = roleRepository.GetCommonTenantRolesAsync().Result.First(r => r.Name == "managers");
            Role adminRole      = roleRepository.GetCommonTenantRolesAsync().Result.First(r => r.Name == "admins");

            // ロール明細の登録
            AddNewRecordForInit(new UserRoleMap()
            {
                Role = researcherRole, User = user, TenantMap = userTenantMap
            });
            AddNewRecordForInit(new UserRoleMap()
            {
                Role = managerRole, User = user, TenantMap = userTenantMap
            });
            AddNewRecordForInit(new UserRoleMap()
            {
                Role = adminRole, User = user
            });

            // テナント系DBの初期化
            InitTenant(tenant);

            //コミット
            int result = dbContext.SaveChanges(user.Name);

            // テナント環境の生成
            return(result);
        }
Esempio n. 3
0
        private int CreateInitialDB()
        {
            //ロール作成
            Role userRole = AddNewRecordForInit(new Role()
            {
                Name = "users", DisplayName = "User", SortOrder = 10, IsSystemRole = false
            });
            Role researcherRole = AddNewRecordForInit(new Role()
            {
                Name = "researchers", DisplayName = "Researcher", SortOrder = 20, IsSystemRole = false
            });
            Role managerRole = AddNewRecordForInit(new Role()
            {
                Name = "managers", DisplayName = "Manager", SortOrder = 30, IsSystemRole = false
            });
            Role adminRole = AddNewRecordForInit(new Role()
            {
                Name = "admins", DisplayName = "Admin", SortOrder = 100, IsSystemRole = true
            });

            //メニュー作成
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = userRole, MenuCode = Logic.MenuLogic.DataMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = userRole, MenuCode = Logic.MenuLogic.DataSetMenu.Code.ToString()
            });

            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = researcherRole, MenuCode = Logic.MenuLogic.DataMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = researcherRole, MenuCode = Logic.MenuLogic.DataSetMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = researcherRole, MenuCode = Logic.MenuLogic.PreprocessMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = researcherRole, MenuCode = Logic.MenuLogic.TrainingMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = researcherRole, MenuCode = Logic.MenuLogic.InferenceMenu.Code.ToString()
            });

            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = managerRole, MenuCode = Logic.MenuLogic.TenantSettingMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = managerRole, MenuCode = Logic.MenuLogic.TenantRoleMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = managerRole, MenuCode = Logic.MenuLogic.TenantUserMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = managerRole, MenuCode = Logic.MenuLogic.TenantMenuAccessMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = managerRole, MenuCode = Logic.MenuLogic.TenantResourceMenu.Code.ToString()
            });

            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.TenantMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.GitMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.RegistryMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.StorageMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.RoleMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.QuotaMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.UserMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.NodeMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.ResourceMenu.Code.ToString()
            });
            AddNewRecordForInit(new MenuRoleMap()
            {
                Role = adminRole, MenuCode = Logic.MenuLogic.MenuAccessMenu.Code.ToString()
            });

            //初期Git作成
            Git git = AddNewRecordForInit(new Git()
            {
                Name = "GitHub", RepositoryUrl = "https://github.com", ServiceType = GitServiceType.GitHub, ApiUrl = "https://api.github.com"
            });
            //初期レジストリ作成
            Registry registry = AddNewRecordForInit(new Registry()
            {
                Name = "official-docker-hub", Host = "registry.hub.docker.com", PortNo = 80, ServiceType = RegistryServiceType.DockerHub, ApiUrl = "https://registry.hub.docker.com/", RegistryUrl = "https://registry.hub.docker.com/"
            });

            // 初期ノードの作成
            string[] nodeNames = deployOptions.GpuNodes.Split(',');
            foreach (string nodeName in nodeNames)
            {
                AddNewRecordForInit(new Node()
                {
                    Name               = nodeName,
                    AccessLevel        = NodeAccessLevel.Public,
                    TensorBoardEnabled = true
                });
            }

            // 初期ストレージの作成
            Storage storage = AddNewRecordForInit(new Storage()
            {
                Name          = ApplicationConst.DefaultFirstStorageName,
                ServerAddress = deployOptions.ObjectStorageNode + ":" + deployOptions.ObjectStoragePort,
                AccessKey     = deployOptions.ObjectStorageAccessKey,
                SecretKey     = deployOptions.ObjectStorageSecretKey,
                NfsServer     = deployOptions.NfsStorage,
                NfsRoot       = deployOptions.NfsPath
            });

            //初期テナント作成
            Tenant tenant = AddNewRecordForInit(new Tenant()
            {
                Name              = ApplicationConst.DefaultFirstTenantName,
                DisplayName       = ApplicationConst.DefaultFirstTenantDisplayName,
                DefaultGit        = git,
                DefaultRegistryId = registry.Id,
                StorageBucket     = ApplicationConst.DefaultFirstTenantName,
                StorageId         = storage.Id
            });
            //GitとTenantの対応付け
            TenantGitMap tenantGitMap = AddNewRecordForInit(new TenantGitMap()
            {
                Tenant = tenant, Git = git
            });
            //RegistryとTenantの対応付け
            TenantRegistryMap tenantRegistryMap = AddNewRecordForInit(new TenantRegistryMap()
            {
                Tenant = tenant, Registry = registry
            });

            //初期ユーザ作成
            User user = AddNewRecordForInit(new User()
            {
                Name          = ApplicationConst.DefaultFirstAdminUserName,
                ServiceType   = AuthServiceType.Local,
                DefaultTenant = tenant,
                Password      = Util.GenerateHash(deployOptions.Password, ApplicationConst.DefaultFirstAdminUserName)
            });

            //初期ユーザの所属登録
            UserTenantMap userTenantMap = AddNewRecordForInit(new UserTenantMap()
            {
                Tenant = tenant, User = user
            });

            AddNewRecordForInit(new UserTenantGitMap()
            {
                User = user, TenantGitMap = tenantGitMap
            });
            AddNewRecordForInit(new UserTenantRegistryMap()
            {
                User = user, TenantRegistryMap = tenantRegistryMap
            });

            // ロール明細の登録

            AddNewRecordForInit(new UserRoleMap()
            {
                Role = researcherRole, User = user, TenantMap = userTenantMap
            });
            AddNewRecordForInit(new UserRoleMap()
            {
                Role = managerRole, User = user, TenantMap = userTenantMap
            });
            AddNewRecordForInit(new UserRoleMap()
            {
                Role = adminRole, User = user
            });

            // テナント系DBの初期化
            InitTenant(tenant);

            //コミット
            int result = dbContext.SaveChanges(user.Name);

            // テナント環境の生成
            return(result);
        }