protected void assignTemplate(final Account env) { if (env.getProjectTemplateId() != null) { return; } final ProjectTemplate template = objectManager.findAny(ProjectTemplate.class, PROJECT_TEMPLATE.IS_PUBLIC, true, PROJECT_TEMPLATE.REMOVED, null, PROJECT_TEMPLATE.NAME, CatalogService.DEFAULT_TEMPLATE.get()); if (template == null) { throw new IllegalStateException("Failed to find default template for upgrade"); } DeferredUtils.nest(new Runnable() { @Override public void run() { systemStackTrigger.trigger(env.getId()); objectManager.setFields(env, ACCOUNT.PROJECT_TEMPLATE_ID, template.getId()); } }); }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Account account = (Account)state.getResource(); if (account.getProjectTemplateId() != null || !AccountConstants.PROJECT_KIND.equals(account.getKind())) { return null; } if (StringUtils.isBlank(DEFAULT_TEMPLATE.get())) { return null; } ProjectTemplate template = objectManager.findAny(ProjectTemplate.class, PROJECT_TEMPLATE.NAME, DEFAULT_TEMPLATE.get(), PROJECT_TEMPLATE.IS_PUBLIC, true, PROJECT_TEMPLATE.REMOVED, null); return new HandlerResult( ACCOUNT.PROJECT_TEMPLATE_ID, template == null ? null : template.getId()); }
public List<Long> createStacks(Account account) throws IOException { List<Long> createdStackIds = DataAccessor.fieldLongList(account, AccountConstants.FIELD_CREATED_STACKS); if (!createdStackIds.isEmpty()) { return createdStackIds; } ProjectTemplate projectTemplate = objectManager.loadResource(ProjectTemplate.class, account.getProjectTemplateId()); if (projectTemplate == null) { return Collections.emptyList(); } List<CatalogTemplate> templates = DataAccessor.fieldObjectList(projectTemplate, ProjectTemplateConstants.FIELD_STACKS, CatalogTemplate.class, jsonMapper); Map<String, CatalogTemplate> templatesById = catalogService.resolvedExternalIds(templates); createdStackIds = new ArrayList<>(); boolean executorRunning = false; for (Map.Entry<String, CatalogTemplate> entry : templatesById.entrySet()) { String externalId = entry.getKey(); Stack stack = objectManager.findAny(Stack.class, STACK.ACCOUNT_ID, account.getId(), STACK.EXTERNAL_ID, externalId, STACK.REMOVED, null); if (stack == null) { executorRunning = waitForExecutor(executorRunning); stack = catalogService.deploy(account.getId(), entry.getValue()); } createdStackIds.add(stack.getId()); } objectManager.reload(account); objectManager.setFields(account, AccountConstants.FIELD_CREATED_STACKS, createdStackIds); return createdStackIds; }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { ProjectTemplate template = (ProjectTemplate)state.getResource(); if (!Boolean.TRUE.equals(template.getIsPublic()) || !CatalogService.DEFAULT_TEMPLATE.get().equalsIgnoreCase(template.getName())) { return null; } sampleDataStartupV3.start(); Account defaultProject = getDefaultProject(); if (defaultProject == null || defaultProject.getProjectTemplateId() != null) { return null; } if (!AccountConstants.ACCOUNT_VERSION.get().equals(defaultProject.getVersion())) { return null; } Long projectTemplateId = defaultProject.getProjectTemplateId(); if (projectTemplateId == null) { projectTemplateId = template.getId(); } systemStackTrigger.trigger(defaultProject.getId()); objectManager.setFields(defaultProject, ACCOUNT.PROJECT_TEMPLATE_ID, projectTemplateId); return null; }
@Override public Object create(String type, ApiRequest request, ResourceManager next) { Account account = request.proxyRequestObject(Account.class); ProjectTemplate template = objectManager.loadResource(ProjectTemplate.class, account.getProjectTemplateId()); if (template == null) { return super.create(type, request, next); } List<CatalogTemplate> templates = DataAccessor.fieldObjectList(template, ProjectTemplateConstants.FIELD_STACKS, CatalogTemplate.class, jsonMapper); if (templates == null) { return super.create(type, request, next); } List<String> ids = new ArrayList<>(); for (CatalogTemplate catalogTemplate : templates) { String id = catalogTemplate.getTemplateVersionId(); if (StringUtils.isBlank(id)) { id = catalogTemplate.getTemplateId(); } if (StringUtils.isNotBlank(id)) { ids.add(id); } } Map<String, Object> input = CollectionUtils.toMap(request.getRequestObject()); input.put(AccountConstants.FIELD_ORCHESTRATION, SystemStackUpdate.chooseOrchestration(ids)); return super.create(type, request, next); }
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.Account from) { setId(from.getId()); setName(from.getName()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setExternalId(from.getExternalId()); setExternalIdType(from.getExternalIdType()); setHealthState(from.getHealthState()); setProjectTemplateId(from.getProjectTemplateId()); setDefaultNetworkId(from.getDefaultNetworkId()); setVersion(from.getVersion()); setRevision(from.getRevision()); }