This is an automated email from the ASF dual-hosted git repository. benyoka pushed a commit to branch branch-feature-AMBARI-14714 in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by this push: new 2d8d32a AMBARI-22776 Ambari Blueprint 3.0/3.1 database tables and JPA objects + DDL cleanup (#109) (benyoka) 2d8d32a is described below commit 2d8d32a2455851b44e6cd597825371286bcdc459 Author: benyoka <beny...@users.noreply.github.com> AuthorDate: Wed Jan 24 20:54:50 2018 +0100 AMBARI-22776 Ambari Blueprint 3.0/3.1 database tables and JPA objects + DDL cleanup (#109) (benyoka) * AMBARI-22776 Blueprint 3.0 Database schemas and JPA objects, DDL fixes (benyoka) * AMBARI-22776 Revert accidental commit (benyoka) * AMBARI-22776 Revert accidental change #2 (benyoka) * AMBARI-22776 Fix review findings (benyoka) * AMBARI-22776 Fix review findings #2 (benyoka) * AMBARI-22776 remove blueprint -> stack reference, docs (benyoka) * AMBARI-22776 fix build issues (benyoka) * AMBARI-22776 Add MpackInstanceEntity -> MpackEntity reference (benyoka) --- .../internal/BlueprintResourceProvider.java | 12 +- .../apache/ambari/server/orm/dao/BlueprintDAO.java | 14 -- .../server/orm/entities/BlueprintEntity.java | 46 ++--- .../orm/entities/BlueprintMpackConfigEntity.java | 149 ++++++++++++++++ .../orm/entities/BlueprintMpackConfigEntityPk.java | 51 ++++++ .../orm/entities/BlueprintMpackInstanceEntity.java | 190 +++++++++++++++++++++ .../orm/entities/BlueprintServiceConfigEntity.java | 147 ++++++++++++++++ .../entities/BlueprintServiceConfigEntityPk.java | 52 ++++++ .../orm/entities/BlueprintServiceEntity.java | 129 ++++++++++++++ .../orm/entities/HostGroupComponentEntity.java | 87 +++++++++- .../orm/entities/HostGroupComponentEntityPK.java | 116 ------------- .../server/orm/entities/HostGroupEntity.java | 7 +- .../ambari/server/topology/BlueprintImpl.java | 9 - .../src/main/resources/Ambari-DDL-Derby-CREATE.sql | 72 +++++--- .../src/main/resources/Ambari-DDL-MySQL-CREATE.sql | 80 +++++---- .../main/resources/Ambari-DDL-Oracle-CREATE.sql | 81 +++++---- .../main/resources/Ambari-DDL-Postgres-CREATE.sql | 50 +++++- .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 69 +++++--- .../main/resources/Ambari-DDL-SQLServer-CREATE.sql | 76 ++++++--- .../src/main/resources/META-INF/persistence.xml | 4 + .../internal/BlueprintResourceProviderTest.java | 42 ++--- .../org/apache/ambari/server/orm/db/DDLTests.java | 43 +++-- .../server/orm/entities/BlueprintEntityTest.java | 7 - .../server/orm/entities/BlueprintEntityTest2.java | 183 ++++++++++++++++++++ 24 files changed, 1341 insertions(+), 375 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java index c665aec..b9899bd 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java @@ -46,10 +46,10 @@ import org.apache.ambari.server.orm.dao.BlueprintDAO; import org.apache.ambari.server.orm.entities.BlueprintConfigEntity; import org.apache.ambari.server.orm.entities.BlueprintConfiguration; import org.apache.ambari.server.orm.entities.BlueprintEntity; +import org.apache.ambari.server.orm.entities.BlueprintMpackInstanceEntity; import org.apache.ambari.server.orm.entities.BlueprintSettingEntity; import org.apache.ambari.server.orm.entities.HostGroupComponentEntity; import org.apache.ambari.server.orm.entities.HostGroupEntity; -import org.apache.ambari.server.orm.entities.StackEntity; import org.apache.ambari.server.stack.NoSuchStackException; import org.apache.ambari.server.state.SecurityType; import org.apache.ambari.server.state.StackInfo; @@ -309,11 +309,8 @@ public class BlueprintResourceProvider extends AbstractControllerResourceProvide * @return a new resource instance for the given blueprint entity */ protected Resource toResource(BlueprintEntity entity, Set<String> requestedIds) throws NoSuchResourceException { - StackEntity stackEntity = entity.getStack(); Resource resource = new ResourceImpl(Resource.Type.Blueprint); setResourceProperty(resource, BLUEPRINT_NAME_PROPERTY_ID, entity.getBlueprintName(), requestedIds); - setResourceProperty(resource, STACK_NAME_PROPERTY_ID, stackEntity.getStackName(), requestedIds); - setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, stackEntity.getStackVersion(), requestedIds); List<Map<String, Object>> listGroupProps = new ArrayList<>(); Collection<HostGroupEntity> hostGroups = entity.getHostGroups(); @@ -377,11 +374,14 @@ public class BlueprintResourceProvider extends AbstractControllerResourceProvide Map<String, String> properties = jsonSerializer.<Map<String, String>>fromJson( config.getConfigData(), Map.class); - StackEntity stack = ((BlueprintConfigEntity)config).getBlueprintEntity().getStack(); + + // TODO: use multiple mpacks + BlueprintMpackInstanceEntity mpack = + ((BlueprintConfigEntity)config).getBlueprintEntity().getMpackReferences().iterator().next(); StackInfo metaInfoStack; try { - metaInfoStack = ambariMetaInfo.getStack(stack.getStackName(), stack.getStackVersion()); + metaInfoStack = ambariMetaInfo.getStack(mpack.getMpackName(), mpack.getMpackVersion()); } catch (AmbariException e) { throw new NoSuchResourceException(e.getMessage()); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java index b74506c..70ee514 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java @@ -18,7 +18,6 @@ package org.apache.ambari.server.orm.dao; - import java.util.List; import javax.persistence.EntityManager; @@ -26,14 +25,12 @@ import javax.persistence.TypedQuery; import org.apache.ambari.server.orm.RequiresSession; import org.apache.ambari.server.orm.entities.BlueprintEntity; -import org.apache.ambari.server.orm.entities.StackEntity; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; import com.google.inject.persist.Transactional; - /** * Blueprint Data Access Object. */ @@ -82,7 +79,6 @@ public class BlueprintDAO { */ @Transactional public void refresh(BlueprintEntity blueprintEntity) { - ensureStackIdSet(blueprintEntity); entityManagerProvider.get().refresh(blueprintEntity); } @@ -93,7 +89,6 @@ public class BlueprintDAO { */ @Transactional public void create(BlueprintEntity blueprintEntity) { - ensureStackIdSet(blueprintEntity); entityManagerProvider.get().persist(blueprintEntity); } @@ -105,7 +100,6 @@ public class BlueprintDAO { */ @Transactional public BlueprintEntity merge(BlueprintEntity blueprintEntity) { - ensureStackIdSet(blueprintEntity); return entityManagerProvider.get().merge(blueprintEntity); } @@ -116,7 +110,6 @@ public class BlueprintDAO { */ @Transactional public void remove(BlueprintEntity blueprintEntity) { - ensureStackIdSet(blueprintEntity); entityManagerProvider.get().remove(merge(blueprintEntity)); } @@ -128,11 +121,4 @@ public class BlueprintDAO { public void removeByName(String blueprint_name) { entityManagerProvider.get().remove(findByName(blueprint_name)); } - - private void ensureStackIdSet(BlueprintEntity entity) { - StackEntity stack = entity.getStack(); - if (stack != null && stack.getStackId() == null) { - entity.setStack(stackDAO.find(stack.getStackName(), stack.getStackVersion())); - } - } } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java index bab393a..31cbf86 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintEntity.java @@ -18,6 +18,7 @@ package org.apache.ambari.server.orm.entities; +import java.util.ArrayList; import java.util.Collection; import javax.persistence.Basic; @@ -27,10 +28,8 @@ import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.Id; -import javax.persistence.JoinColumn; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; -import javax.persistence.OneToOne; import javax.persistence.Table; import org.apache.ambari.server.state.SecurityType; @@ -58,22 +57,18 @@ public class BlueprintEntity { @Basic @Column(name = "security_descriptor_reference", nullable = true, insertable = true, updatable = true) private String securityDescriptorReference; - - /** - * Unidirectional one-to-one association to {@link StackEntity} - */ - @OneToOne - @JoinColumn(name = "stack_id", unique = false, nullable = false, insertable = true, updatable = false) - private StackEntity stack; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint") + private Collection<HostGroupEntity> hostGroups = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint") - private Collection<HostGroupEntity> hostGroups; + private Collection<BlueprintConfigEntity> configurations = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint") - private Collection<BlueprintConfigEntity> configurations; + private Collection<BlueprintSettingEntity> settings = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, mappedBy = "blueprint") - private Collection<BlueprintSettingEntity> settings; + private Collection<BlueprintMpackInstanceEntity> mpackReferences = new ArrayList<>(); /** @@ -95,25 +90,6 @@ public class BlueprintEntity { } /** - * Gets the blueprint's stack. - * - * @return the stack. - */ - public StackEntity getStack() { - return stack; - } - - /** - * Sets the blueprint's stack. - * - * @param stack - * the stack to set for the blueprint (not {@code null}). - */ - public void setStack(StackEntity stack) { - this.stack = stack; - } - - /** * Get the collection of associated host groups. * * @return collection of host groups @@ -182,4 +158,12 @@ public class BlueprintEntity { public void setSecurityDescriptorReference(String securityDescriptorReference) { this.securityDescriptorReference = securityDescriptorReference; } + + public Collection<BlueprintMpackInstanceEntity> getMpackReferences() { + return mpackReferences; + } + + public void setMpackReferences(Collection<BlueprintMpackInstanceEntity> mpackReferences) { + this.mpackReferences = mpackReferences; + } } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackConfigEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackConfigEntity.java new file mode 100644 index 0000000..50cb0d2 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackConfigEntity.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.entities; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * Entity to represent an mpack level configuration in the blueprint. + */ +@Entity +@Table(name = "blueprint_mpack_configuration") +@IdClass(BlueprintMpackConfigEntityPk.class) +public class BlueprintMpackConfigEntity implements BlueprintConfiguration { + + @Id + @Column(name = "mpack_ref_id", nullable = false, insertable = false, updatable = false) + private Long mpackRefId; + + @Id + @Column(name = "type_name", nullable = false, insertable = true, updatable = false, length = 100) + private String type; + + @Column(name = "config_data") + @Basic(fetch = FetchType.LAZY) + @Lob + private String configData; + + @Column(name = "config_attributes") + @Basic(fetch = FetchType.LAZY) + @Lob + private String configAttributes; + + @ManyToOne + @JoinColumn(name = "mpack_ref_id", referencedColumnName = "id", nullable = false) + private BlueprintMpackInstanceEntity mpackReference; + + /** + * @return the id of the mpack referency entity this configuration belongs to + */ + public Long getMpackRefId() { + return mpackRefId; + } + + /** + * @param mpackRefId the id of the mpack referency entity this configuration belongs to + */ + public void setMpackRefId(Long mpackRefId) { + this.mpackRefId = mpackRefId; + } + + /** + * @return the configuration type + */ + @Override + public String getType() { + return type; + } + + /** + * @param typeName the type of the configuration + */ + @Override + public void setType(String typeName) { + this.type = typeName; + } + + /** + * @return the configuration data encoded in json + */ + public String getConfigData() { + return configData; + } + + /** + * @param blueprintName the name of the blueprint + */ + @Override + public void setBlueprintName(String blueprintName) { + throw new UnsupportedOperationException(); + } + + /** + * @return the name of the blueprint + */ + @Override + public String getBlueprintName() { + return getMpackReference().getBlueprint().getBlueprintName(); + } + + /** + * @param configData the configuration data encoded in json + */ + public void setConfigData(String configData) { + this.configData = configData; + } + + /** + * @return the configuration attributes encoded in json + */ + public String getConfigAttributes() { + return configAttributes; + } + + /** + * @param configAttributes the configuration attributes encoded in json + */ + public void setConfigAttributes(String configAttributes) { + this.configAttributes = configAttributes; + } + + /** + * @return the mpack referency entity this configuration belongs to + */ + public BlueprintMpackInstanceEntity getMpackReference() { + return mpackReference; + } + + /** + * @param mpackReference the mpack referency entity this configuration belongs to + */ + public void setMpackReference(BlueprintMpackInstanceEntity mpackReference) { + this.mpackReference = mpackReference; + } +} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackConfigEntityPk.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackConfigEntityPk.java new file mode 100644 index 0000000..6f4f017 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackConfigEntityPk.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.entities; + +import java.util.Objects; + +import javax.persistence.Column; +import javax.persistence.Id; + +/** + * Composite primary key for {@link BlueprintMpackConfigEntity} + */ +public class BlueprintMpackConfigEntityPk { + @Id + @Column(name = "mpack_ref_id", nullable = false, insertable = true, updatable = false) + private Long mpackRefId; + + @Id + @Column(name = "type_name", nullable = false, insertable = true, updatable = false, length = 100) + private String type; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BlueprintMpackConfigEntityPk that = (BlueprintMpackConfigEntityPk) o; + return Objects.equals(mpackRefId, that.mpackRefId) && + Objects.equals(type, that.type); + } + + @Override + public int hashCode() { + return Objects.hash(mpackRefId, type); + } +} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackInstanceEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackInstanceEntity.java new file mode 100644 index 0000000..c87d994 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintMpackInstanceEntity.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.entities; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.annotation.Nullable; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; + +/** + * Entity to encapsulate a blueprint's use of an mpack. It contains the mpack name, version, url + * + * + * referencing a management pack from the blueprint. The reference contains the name and + * the version of the mpack, but no direct database reference to the mpack entity as a blueprint + * can be saved without the referenced mpack being present. + */ +@Entity +@Table(name = "blueprint_mpack_instance") +@TableGenerator(name = "blueprint_mpack_instance_id_generator", table = "ambari_sequences", pkColumnName = "sequence_name", + valueColumnName = "sequence_value", pkColumnValue = "blueprint_mpack_instance_id_seq", initialValue = 1) +public class BlueprintMpackInstanceEntity { + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "blueprint_mpack_reference_id_generator") + @Column(name = "id", nullable = false, updatable = false) + private Long id; + + @Column(name = "mpack_name") + private String mpackName; + + @Column(name = "mpack_version") + private String mpackVersion; + + @Column(name = "mpack_uri") + private String mpackUri; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "mpackReference") + private Collection<BlueprintServiceEntity> serviceInstances = new ArrayList<>(); + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "mpackReference") + private Collection<BlueprintMpackConfigEntity> configurations = new ArrayList<>(); + + @ManyToOne + @JoinColumn(name = "mpack_id", referencedColumnName = "id", nullable = true) + private MpackEntity mpackEntity; + + @ManyToOne + @JoinColumn(name = "blueprint_name", referencedColumnName = "blueprint_name", nullable = false) + private BlueprintEntity blueprint; + + /** + * @return the service instances belonging to this mpack + */ + public Collection<BlueprintServiceEntity> getServiceInstances() { + return serviceInstances; + } + + /** + * @param serviceInstances the service instances belonging to this mpack + */ + public void setServiceInstances(Collection<BlueprintServiceEntity> serviceInstances) { + this.serviceInstances = serviceInstances; + } + + /** + * @return the name of the mpack + */ + public String getMpackName() { + return mpackName; + } + + /** + * @param mpackName the name of the mpack + */ + public void setMpackName(String mpackName) { + this.mpackName = mpackName; + } + + /** + * @return the version of the mpack + */ + public String getMpackVersion() { + return mpackVersion; + } + + /** + * @param mpackVersion the version of the mpack + */ + public void setMpackVersion(String mpackVersion) { + this.mpackVersion = mpackVersion; + } + + /** + * @return the uri of the mpack + */ + public String getMpackUri() { + return mpackUri; + } + + /** + * @param mpackUri the uri of the mpack + */ + public void setMpackUri(String mpackUri) { + this.mpackUri = mpackUri; + } + + /** + * @return the database id + */ + public Long getId() { + return id; + } + + /** + * @param id the database id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return the blueprint + */ + public BlueprintEntity getBlueprint() { + return blueprint; + } + + /** + * @param blueprint the blueprint + */ + public void setBlueprint(BlueprintEntity blueprint) { + this.blueprint = blueprint; + } + + /** + * @return the mpack level configurations for this mpack + */ + public Collection<BlueprintMpackConfigEntity> getConfigurations() { + return configurations; + } + + /** + * @param configurations the mpack level configurations for this mpack + */ + public void setConfigurations(Collection<BlueprintMpackConfigEntity> configurations) { + this.configurations = configurations; + } + + /** + * @return the management pack entity associated with this blueprint. Can be {@null} + */ + @Nullable + public MpackEntity getMpackEntity() { + return mpackEntity; + } + + /** + * @param mpackEntity the management pack entity to be associated with this blueprint. + */ + public void setMpackEntity(MpackEntity mpackEntity) { + this.mpackEntity = mpackEntity; + } +} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceConfigEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceConfigEntity.java new file mode 100644 index 0000000..3dd8892 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceConfigEntity.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.entities; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * Entity representing a blueprint service instance configuration + */ +@Entity +@Table(name = "blueprint_service_config") +@IdClass(BlueprintServiceConfigEntityPk.class) +public class BlueprintServiceConfigEntity implements BlueprintConfiguration { + + @Id + @Column(name = "service_id", nullable = false, insertable = false, updatable = false) + private Long serviceId; + + @Id + @Column(name = "type_name", nullable = false, insertable = true, updatable = false, length = 100) + private String type; + + @Column(name = "config_data") + @Basic(fetch = FetchType.LAZY) + @Lob + private String configData; + + @Column(name = "config_attributes") + @Basic(fetch = FetchType.LAZY) + @Lob + private String configAttributes; + + @ManyToOne + @JoinColumn(name = "service_id", referencedColumnName = "id", nullable = false) + private BlueprintServiceEntity service; + + /** + * @return the database id of the service instance + */ + public Long getServiceId() { + return serviceId; + } + + /** + * @param serviceId the database id of the service instance + */ + public void setServiceId(Long serviceId) { + this.serviceId = serviceId; + } + + /** + * @return the type of the configuration + */ + public String getType() { + return type; + } + + /** + * @param blueprintName the blueprint name + */ + @Override + public void setBlueprintName(String blueprintName) { + throw new UnsupportedOperationException("BlueprintServiceEntity.setBlueprintName"); + } + + /** + * @return the blueprint name + */ + @Override + public String getBlueprintName() { + return getService().getMpackReference().getBlueprint().getBlueprintName(); + } + + /** + * @param typeName the type of the configuration + */ + public void setType(String typeName) { + this.type = typeName; + } + + /** + * @return the configuration data encoded in json + */ + public String getConfigData() { + return configData; + } + + /** + * @param configData the configuration data encoded in json + */ + public void setConfigData(String configData) { + this.configData = configData; + } + + /** + * @return the configuration attributes encoded in json + */ + public String getConfigAttributes() { + return configAttributes; + } + + /** + * @param configAttributes the configuration attributes encoded in json + */ + public void setConfigAttributes(String configAttributes) { + this.configAttributes = configAttributes; + } + + /** + * @return the service instance this configuration belongs to + */ + public BlueprintServiceEntity getService() { + return service; + } + + /** + * @param service the service instance this configuration belongs to + */ + public void setService(BlueprintServiceEntity service) { + this.service = service; + } +} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceConfigEntityPk.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceConfigEntityPk.java new file mode 100644 index 0000000..6c13fb7 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceConfigEntityPk.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.entities; + +import java.util.Objects; + +import javax.persistence.Column; +import javax.persistence.Id; + +/** + * Composite primary key for {@link BlueprintServiceConfigEntity} + */ +public class BlueprintServiceConfigEntityPk { + + @Id + @Column(name = "service_id", nullable = false, insertable = true, updatable = false) + private Long serviceId; + + @Id + @Column(name = "type_name", nullable = false, insertable = true, updatable = false, length = 100) + private String type; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BlueprintServiceConfigEntityPk that = (BlueprintServiceConfigEntityPk) o; + return Objects.equals(serviceId, that.serviceId) && + Objects.equals(type, that.type); + } + + @Override + public int hashCode() { + return Objects.hash(serviceId, type); + } +} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceEntity.java new file mode 100644 index 0000000..cbca473 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/BlueprintServiceEntity.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.entities; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.TableGenerator; + +/** + * Entity representing a service instance in multi-service blueprints + */ +@Entity +@Table(name = "blueprint_service") +@TableGenerator(name = "blueprint_service_id_generator", table = "ambari_sequences", pkColumnName = "sequence_name", + valueColumnName = "sequence_value", pkColumnValue = "blueprint_service_id_seq", initialValue = 1) +public class BlueprintServiceEntity { + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "blueprint_service_id_generator") + @Column(name = "id", nullable = false, updatable = false) + private Long id; + + @ManyToOne() + @JoinColumn(name = "mpack_ref_id", referencedColumnName = "id", nullable = false) + private BlueprintMpackInstanceEntity mpackReference; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "service") + private Collection<BlueprintServiceConfigEntity> configurations = new ArrayList<>(); + + private String name; + + private String type; + + /** + * @return the database id + */ + public Long getId() { + return id; + } + + /** + * @param id the database id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return the mpack reference to the mpack associated with this service + */ + public BlueprintMpackInstanceEntity getMpackReference() { + return mpackReference; + } + + /** + * @param mpackReference the mpack reference to the mpack associated with this service + */ + public void setMpackReference(BlueprintMpackInstanceEntity mpackReference) { + this.mpackReference = mpackReference; + } + + /** + * @return the service instance level configuration entities + */ + public Collection<BlueprintServiceConfigEntity> getConfigurations() { + return configurations; + } + + /** + * @param configurations the service instance level configuration entities + */ + public void setConfigurations(Collection<BlueprintServiceConfigEntity> configurations) { + this.configurations = configurations; + } + + /** + * @return the name of this service instance + */ + public String getName() { + return name; + } + + /** + * @param name the name of this service instance + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the configuration type + */ + public String getType() { + return type; + } + + /** + * @param type the configuration type + */ + public void setType(String type) { + this.type = type; + } +} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java index 6b75df7..f16ef40 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntity.java @@ -20,36 +20,50 @@ package org.apache.ambari.server.orm.entities; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; -import javax.persistence.IdClass; import javax.persistence.JoinColumn; import javax.persistence.JoinColumns; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.persistence.TableGenerator; /** * Represents a Host Group Component which is embedded in a Blueprint. */ -@IdClass(HostGroupComponentEntityPK.class) -@Table(name = "hostgroup_component") @Entity +@Table(name = "hostgroup_component") +@TableGenerator(name = "hostgroup_component_id_generator", table = "ambari_sequences", pkColumnName = "sequence_name", + valueColumnName = "sequence_value", pkColumnValue = "hostgroup_component_id_seq", initialValue = 1) public class HostGroupComponentEntity { @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "hostgroup_component_id_generator") + @Column(name = "id", nullable = false, updatable = false) + private Long id; + @Column(name = "hostgroup_name", nullable = false, insertable = false, updatable = false) private String hostGroupName; - @Id @Column(name = "blueprint_name", nullable = false, insertable = false, updatable = false) private String blueprintName; - @Id @Column(name = "name", nullable = false, insertable = true, updatable = false) private String name; @Column(name = "provision_action", nullable = true, insertable = true, updatable = false) private String provisionAction; + @Column(name = "mpack_name", nullable = true, insertable = true, updatable = false) + private String mpackName; + + @Column(name = "mpack_version", nullable = true, insertable = true, updatable = false) + private String mpackVersion; + + @Column(name = "service_name", nullable = true, insertable = true, updatable = false) + private String serviceName; + @ManyToOne @JoinColumns({ @JoinColumn(name = "hostgroup_name", referencedColumnName = "name", nullable = false), @@ -57,7 +71,6 @@ public class HostGroupComponentEntity { }) private HostGroupEntity hostGroup; - /** * Get the name of the host group component. * @@ -149,4 +162,66 @@ public class HostGroupComponentEntity { public void setProvisionAction(String provisionAction) { this.provisionAction = provisionAction; } + + /** + * @return the database id + */ + public Long getId() { + return id; + } + + /** + * @param id the database id + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return the name of the mpack defining this component + * (only needs to be set if multiple mpack define the same component) + */ + public String getMpackName() { + return mpackName; + } + + /** + * @param mpackName the name of the mpack defining this component + * (only needs to be set if multiple mpack define the same component) + */ + public void setMpackName(String mpackName) { + this.mpackName = mpackName; + } + + /** + * @return the version of the mpack defining this component + * (only needs to be set if multiple mpack define the same component) + */ + public String getMpackVersion() { + return mpackVersion; + } + + /** + * @param mpackVersion the version of the mpack defining this component + * (only needs to be set if multiple mpack define the same component) + */ + public void setMpackVersion(String mpackVersion) { + this.mpackVersion = mpackVersion; + } + + /** + * @return the name of the service instance defining this component + * (only needs to be set if component resolution would be ambigous otherwise) + */ + public String getServiceName() { + return serviceName; + } + + /** + * @param serviceName the name of the service instance defining this component + * (only needs to be set if component resolution would be ambigous otherwise) + */ + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntityPK.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntityPK.java deleted file mode 100644 index 0d99d79..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupComponentEntityPK.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.orm.entities; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Id; - -/** - * Composite primary key for HostGroupComponentEntity. - */ -public class HostGroupComponentEntityPK implements Serializable { - - @Id - @Column(name = "hostgroup_name", nullable = false, insertable = true, updatable = false, length = 100) - private String hostGroupName; - - @Id - @Column(name = "blueprint_name", nullable = false, insertable = true, updatable = false, length = 100) - private String blueprintName; - - @Id - @Column(name = "name", nullable = false, insertable = true, updatable = false, length = 100) - private String name; - - /** - * Get the name of the associated host group. - * - * @return host group name - */ - public String getHostGroupName() { - return hostGroupName; - } - - /** - * Set the name of the associated host group. - * - * @param hostGroupName host group name - */ - public void setHostGroupName(String hostGroupName) { - this.hostGroupName = hostGroupName; - } - - /** - * Get the name of the associated blueprint. - * - * @return blueprint name - */ - public String getBlueprintName() { - return blueprintName; - } - - /** - * Set the name of the associated blueprint. - * - * @param blueprintName blueprint name - */ - public void setBlueprintName(String blueprintName) { - this.blueprintName = blueprintName; - } - - /** - * Get the name of the host group component. - * - * @return component name - */ - public String getName() { - return name; - } - - /** - * Set the name of the host group component. - * - * @param name component name - */ - public void setName(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - HostGroupComponentEntityPK that = (HostGroupComponentEntityPK) o; - - return this.hostGroupName.equals(that.hostGroupName) && - this.name.equals(that.name) && - this.blueprintName.equals(that.blueprintName); - } - - @Override - public int hashCode() { - int result = hostGroupName.hashCode(); - result = 31 * result + blueprintName.hashCode(); - result = 31 * result + name.hashCode(); - return result; - } -} diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupEntity.java index 8a170a5..a3e7952 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostGroupEntity.java @@ -18,6 +18,7 @@ package org.apache.ambari.server.orm.entities; +import java.util.ArrayList; import java.util.Collection; import javax.persistence.Basic; @@ -51,10 +52,10 @@ public class HostGroupEntity { private String cardinality = "NOT SPECIFIED"; @OneToMany(cascade = CascadeType.ALL, mappedBy = "hostGroup") - private Collection<HostGroupComponentEntity> components; + private Collection<HostGroupComponentEntity> components = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, mappedBy = "hostGroup") - private Collection<HostGroupConfigEntity> configurations; + private Collection<HostGroupConfigEntity> configurations = new ArrayList<>(); @ManyToOne @JoinColumn(name = "blueprint_name", referencedColumnName = "blueprint_name", nullable = false) @@ -108,7 +109,7 @@ public class HostGroupEntity { /** * Set the name of the associated blueprint. - * ' + * * @param blueprintName blueprint name */ public void setBlueprintName(String blueprintName) { diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java index be3547a..1552a6c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImpl.java @@ -66,8 +66,6 @@ public class BlueprintImpl implements Blueprint { null); } - parseStack(entity.getStack()); - // create config first because it is set as a parent on all host-group configs processConfiguration(entity.getConfigurations()); parseBlueprintHostGroups(entity); @@ -333,13 +331,6 @@ public class BlueprintImpl implements Blueprint { } } - //todo: not using stackDAO so stackEntity.id is not set - //todo: this is now being set in BlueprintDAO - StackEntity stackEntity = new StackEntity(); - stackEntity.setStackName(stack.getName()); - stackEntity.setStackVersion(stack.getVersion()); - entity.setStack(stackEntity); - createHostGroupEntities(entity); createBlueprintConfigEntities(entity); createBlueprintSettingEntities(entity); diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql index f8260ef..997e6be 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql @@ -96,25 +96,6 @@ CREATE TABLE configuration_base ( CONSTRAINT PK_configuration_base PRIMARY KEY (id) ); -CREATE TABLE clusterconfig ( - config_id BIGINT NOT NULL, - version_tag VARCHAR(255) NOT NULL, - version BIGINT NOT NULL, - type_name VARCHAR(255) NOT NULL, - cluster_id BIGINT NOT NULL, - stack_id BIGINT NOT NULL, - selected SMALLINT NOT NULL DEFAULT 0, - config_data VARCHAR(3000) NOT NULL, - config_attributes VARCHAR(3000), - create_timestamp BIGINT NOT NULL, - unmapped SMALLINT NOT NULL DEFAULT 0, - selected_timestamp BIGINT NOT NULL DEFAULT 0, - CONSTRAINT PK_clusterconfig PRIMARY KEY (config_id), - CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), - CONSTRAINT FK_clusterconfig_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id), - CONSTRAINT UQ_config_type_tag UNIQUE (version_tag, type_name, cluster_id), - CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version)); - CREATE TABLE ambari_configuration ( category_name VARCHAR(100) NOT NULL, property_name VARCHAR(100) NOT NULL, @@ -617,9 +598,42 @@ CREATE TABLE blueprint ( blueprint_name VARCHAR(255) NOT NULL, security_type VARCHAR(32) NOT NULL DEFAULT 'NONE', security_descriptor_reference VARCHAR(255), - stack_id BIGINT NOT NULL, - CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name), - CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id)); + CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name)); + +CREATE TABLE blueprint_mpack_instance( + id BIGINT NOT NULL, + blueprint_name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255) NOT NULL, + mpack_version VARCHAR(255) NOT NULL, + mpack_uri VARCHAR(255) NOT NULL, + mpack_id BIGINT, + CONSTRAINT PK_blueprint_mpack_inst PRIMARY KEY (id), + CONSTRAINT FK_mpi_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name), + CONSTRAINT FK_mpi_mpack_id FOREIGN KEY (mpack_id) REFERENCES mpacks(id)); + +CREATE TABLE blueprint_service ( + id BIGINT NOT NULL, + mpack_ref_id BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + CONSTRAINT PK_blueprint_service PRIMARY KEY (id), + CONSTRAINT FK_blueprint_service_mpack_ref FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference(id)); + +CREATE TABLE blueprint_service_config ( + service_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data VARCHAR(3000) NOT NULL, + config_attributes VARCHAR(3000), + CONSTRAINT PK_bp_svc_conf PRIMARY KEY (service_id, type_name), + CONSTRAINT FK_bp_svc_config_to_service FOREIGN KEY (service_id) REFERENCES blueprint_service (id)); + +CREATE TABLE blueprint_mpack_configuration ( + mpack_ref_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data VARCHAR(3000) NOT NULL, + config_attributes VARCHAR(3000), + CONSTRAINT PK_bp_mpack_conf PRIMARY KEY (mpack_ref_id, type_name), + CONSTRAINT FK_bp_mpack_config_to_mpack FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference (id)); CREATE TABLE hostgroup ( blueprint_name VARCHAR(255) NOT NULL, @@ -629,11 +643,15 @@ CREATE TABLE hostgroup ( CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name)); CREATE TABLE hostgroup_component ( + id BIGINT NOT NULL, blueprint_name VARCHAR(255) NOT NULL, hostgroup_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255), + mpack_version VARCHAR(100), + service_name VARCHAR(255), provision_action VARCHAR(255), - CONSTRAINT PK_hostgroup_component PRIMARY KEY (blueprint_name, hostgroup_name, name), + CONSTRAINT PK_hostgroup_component PRIMARY KEY (id), CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name)); CREATE TABLE blueprint_configuration ( @@ -1317,7 +1335,13 @@ INSERT INTO ambari_sequences (sequence_name, sequence_value) union all select 'servicecomponent_version_id_seq', 0 FROM SYSIBM.SYSDUMMY1 union all - select 'hostcomponentdesiredstate_id_seq', 0 FROM SYSIBM.SYSDUMMY1; + select 'hostcomponentdesiredstate_id_seq', 0 FROM SYSIBM.SYSDUMMY1 + union all + select 'blueprint_service_id_seq', 0 FROM SYSIBM.SYSDUMMY1 + union all + select 'blueprint_mpack_instance_id_seq', 0 FROM SYSIBM.SYSDUMMY1 + union all + select 'hostgroup_component_id_seq', 0 FROM SYSIBM.SYSDUMMY1; INSERT INTO adminresourcetype (resource_type_id, resource_type_name) diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql index b7807bc..bc385de 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql @@ -115,25 +115,6 @@ CREATE TABLE configuration_base ( CONSTRAINT PK_configuration_base PRIMARY KEY (id) ); -CREATE TABLE clusterconfig ( - config_id BIGINT NOT NULL, - version_tag VARCHAR(100) NOT NULL, - version BIGINT NOT NULL, - type_name VARCHAR(100) NOT NULL, - cluster_id BIGINT NOT NULL, - stack_id BIGINT NOT NULL, - selected SMALLINT NOT NULL DEFAULT 0, - config_data LONGTEXT NOT NULL, - config_attributes LONGTEXT, - create_timestamp BIGINT NOT NULL, - unmapped SMALLINT NOT NULL DEFAULT 0, - selected_timestamp BIGINT NOT NULL DEFAULT 0, - CONSTRAINT PK_clusterconfig PRIMARY KEY (config_id), - CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), - CONSTRAINT FK_clusterconfig_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id), - CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag), - CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version)); - CREATE TABLE ambari_configuration ( category_name VARCHAR(100) NOT NULL, property_name VARCHAR(100) NOT NULL, @@ -633,11 +614,45 @@ CREATE TABLE requestschedulebatchrequest ( CREATE TABLE blueprint ( blueprint_name VARCHAR(100) NOT NULL, - stack_id BIGINT NOT NULL, security_type VARCHAR(32) NOT NULL DEFAULT 'NONE', security_descriptor_reference VARCHAR(255), - CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name), - CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id)); + CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name)); + +CREATE TABLE blueprint_mpack_instance( + id BIGINT NOT NULL, + blueprint_name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255) NOT NULL, + mpack_version VARCHAR(255) NOT NULL, + mpack_uri VARCHAR(255) NOT NULL, + mpack_id BIGINT, + CONSTRAINT PK_blueprint_mpack_inst PRIMARY KEY (id), + CONSTRAINT FK_mpi_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name), + CONSTRAINT FK_mpi_mpack_id FOREIGN KEY (mpack_id) REFERENCES mpacks(id)); + + +CREATE TABLE blueprint_service ( + id BIGINT NOT NULL, + mpack_ref_id BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + CONSTRAINT PK_blueprint_service PRIMARY KEY (id), + CONSTRAINT FK_blueprint_service_mpack_ref FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference(id)); + +CREATE TABLE blueprint_service_config ( + service_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data LONGTEXT NOT NULL, + config_attributes LONGTEXT, + CONSTRAINT PK_bp_svc_conf PRIMARY KEY (service_id, type_name), + CONSTRAINT FK_bp_svc_config_to_service FOREIGN KEY (service_id) REFERENCES blueprint_service (id)); + +CREATE TABLE blueprint_mpack_configuration ( + mpack_ref_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data LONGTEXT NOT NULL, + config_attributes LONGTEXT, + CONSTRAINT PK_bp_mpack_conf PRIMARY KEY (mpack_ref_id, type_name), + CONSTRAINT FK_bp_mpack_config_to_mpack FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference (id)); CREATE TABLE hostgroup ( blueprint_name VARCHAR(100) NOT NULL, @@ -647,12 +662,16 @@ CREATE TABLE hostgroup ( CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name)); CREATE TABLE hostgroup_component ( - blueprint_name VARCHAR(100) NOT NULL, - hostgroup_name VARCHAR(100) NOT NULL, - name VARCHAR(100) NOT NULL, - provision_action VARCHAR(100), - CONSTRAINT PK_hostgroup_component PRIMARY KEY (blueprint_name, hostgroup_name, name), - CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup(blueprint_name, name)); + id BIGINT NOT NULL, + blueprint_name VARCHAR(255) NOT NULL, + hostgroup_name VARCHAR(255) NOT NULL, + name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255), + mpack_version VARCHAR(100), + service_name VARCHAR(255), + provision_action VARCHAR(255), + CONSTRAINT PK_hostgroup_component PRIMARY KEY (id), + CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name)); CREATE TABLE blueprint_configuration ( blueprint_name VARCHAR(100) NOT NULL, @@ -1272,7 +1291,10 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES ('remote_cluster_id_seq', 0), ('remote_cluster_service_id_seq', 0), ('servicecomponent_version_id_seq', 0), - ('hostcomponentdesiredstate_id_seq', 0); + ('hostcomponentdesiredstate_id_seq', 0), + ('blueprint_service_id_seq', 0), + ('blueprint_mpack_instance_id_seq', 0), + ('hostgroup_component_id_seq', 0); INSERT INTO adminresourcetype (resource_type_id, resource_type_name) VALUES (1, 'AMBARI'), diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql index c4d94d4..04969d8 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -18,7 +18,7 @@ ------create tables--------- CREATE TABLE registries ( - id BIGINT NOT NULL, + id NUMBER(19) NOT NULL, registry_name VARCHAR(255) NOT NULL, registry_type VARCHAR(255) NOT NULL, registry_uri VARCHAR(255) NOT NULL, @@ -26,11 +26,11 @@ CREATE TABLE registries ( CONSTRAINT UQ_registry_name UNIQUE (registry_name)); CREATE TABLE mpacks ( - id BIGINT NOT NULL, + id NUMBER(19) NOT NULL, mpack_name VARCHAR(255) NOT NULL, mpack_version VARCHAR(255) NOT NULL, mpack_uri VARCHAR(255), - registry_id BIGINT, + registry_id NUMBER(19), CONSTRAINT PK_mpacks PRIMARY KEY (id), CONSTRAINT UQ_mpack_name_version UNIQUE(mpack_name, mpack_version), CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id)); @@ -39,7 +39,7 @@ CREATE TABLE stack ( stack_id NUMBER(19) NOT NULL, stack_name VARCHAR2(255) NOT NULL, stack_version VARCHAR2(255) NOT NULL, - current_mpack_id BIGINT, + current_mpack_id NUMBER(19), CONSTRAINT PK_stack PRIMARY KEY (stack_id), CONSTRAINT FK_mpacks FOREIGN KEY (current_mpack_id) REFERENCES mpacks(id), CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version)); @@ -96,25 +96,6 @@ CREATE TABLE configuration_base ( CONSTRAINT PK_configuration_base PRIMARY KEY (id) ); -CREATE TABLE clusterconfig ( - config_id NUMBER(19) NOT NULL, - version_tag VARCHAR2(255) NOT NULL, - version NUMBER(19) NOT NULL, - type_name VARCHAR2(255) NOT NULL, - cluster_id NUMBER(19) NOT NULL, - stack_id NUMBER(19) NOT NULL, - selected NUMBER(1) DEFAULT 0 NOT NULL, - config_data CLOB NOT NULL, - config_attributes CLOB, - create_timestamp NUMBER(19) NOT NULL, - unmapped SMALLINT DEFAULT 0 NOT NULL, - selected_timestamp NUMBER(19) DEFAULT 0 NOT NULL, - CONSTRAINT PK_clusterconfig PRIMARY KEY (config_id), - CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), - CONSTRAINT FK_clusterconfig_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id), - CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag), - CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version)); - CREATE TABLE ambari_configuration ( category_name VARCHAR2(100) NOT NULL, property_name VARCHAR2(100) NOT NULL, @@ -191,7 +172,7 @@ CREATE TABLE clusterconfig ( create_timestamp NUMBER(19) NOT NULL, unmapped SMALLINT DEFAULT 0 NOT NULL, selected_timestamp NUMBER(19) DEFAULT 0 NOT NULL, - service_id BIGINT, + service_id NUMBER(19), CONSTRAINT PK_clusterconfig PRIMARY KEY (config_id), CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), CONSTRAINT FK_clusterconfig_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id), @@ -613,11 +594,44 @@ CREATE TABLE requestschedulebatchrequest ( CREATE TABLE blueprint ( blueprint_name VARCHAR2(255) NOT NULL, - stack_id NUMBER(19) NOT NULL, security_type VARCHAR2(32) DEFAULT 'NONE' NOT NULL, - security_descriptor_reference VARCHAR(255), - CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name), - CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id)); + security_descriptor_reference VARCHAR2(255), + CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name)); + +CREATE TABLE blueprint_mpack_instance( + id NUMBER(19) NOT NULL, + blueprint_name VARCHAR2(255) NOT NULL, + mpack_name VARCHAR2(255) NOT NULL, + mpack_version VARCHAR2(255) NOT NULL, + mpack_uri VARCHAR2(255) NOT NULL, + mpack_id NUMBER(19), + CONSTRAINT PK_blueprint_mpack_inst PRIMARY KEY (id), + CONSTRAINT FK_mpi_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name), + CONSTRAINT FK_mpi_mpack_id FOREIGN KEY (mpack_id) REFERENCES mpacks(id)); + +CREATE TABLE blueprint_service ( + id NUMBER(19) NOT NULL, + mpack_ref_id NUMBER(19) NOT NULL, + name VARCHAR2(255) NOT NULL, + type VARCHAR2(255) NOT NULL, + CONSTRAINT PK_blueprint_service PRIMARY KEY (id), + CONSTRAINT FK_blueprint_service_mpack_ref FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference(id)); + +CREATE TABLE blueprint_service_config ( + service_id NUMBER(19) NOT NULL, + type_name VARCHAR2(255) NOT NULL, + config_data CLOB NOT NULL, + config_attributes CLOB, + CONSTRAINT PK_bp_svc_conf PRIMARY KEY (service_id, type_name), + CONSTRAINT FK_bp_svc_config_to_service FOREIGN KEY (service_id) REFERENCES blueprint_service (id)); + +CREATE TABLE blueprint_mpack_configuration ( + mpack_ref_id NUMBER(19) NOT NULL, + type_name VARCHAR2(255) NOT NULL, + config_data CLOB NOT NULL, + config_attributes CLOB, + CONSTRAINT PK_bp_mpack_conf PRIMARY KEY (mpack_ref_id, type_name), + CONSTRAINT FK_bp_mpack_config_to_mpack FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference (id)); CREATE TABLE hostgroup ( blueprint_name VARCHAR2(255) NOT NULL, @@ -627,12 +641,16 @@ CREATE TABLE hostgroup ( CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name)); CREATE TABLE hostgroup_component ( + id NUMBER(19) NOT NULL, blueprint_name VARCHAR2(255) NOT NULL, hostgroup_name VARCHAR2(255) NOT NULL, name VARCHAR2(255) NOT NULL, + mpack_name VARCHAR2(255), + mpack_version VARCHAR2(100), + service_name VARCHAR2(255), provision_action VARCHAR2(255), - CONSTRAINT PK_hostgroup_component PRIMARY KEY (blueprint_name, hostgroup_name, name), - CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup(blueprint_name, name)); + CONSTRAINT PK_hostgroup_component PRIMARY KEY (id), + CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name)); CREATE TABLE blueprint_configuration ( blueprint_name VARCHAR2(255) NOT NULL, @@ -1251,6 +1269,9 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_clus INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_cluster_service_id_seq', 0); INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('servicecomponent_version_id_seq', 0); INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostcomponentdesiredstate_id_seq', 0); +INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('blueprint_service_id_seq', 0); +INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('blueprint_mpack_instance_id_seq', 0); +INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostgroup_component_id_seq', 0); INSERT INTO metainfo("metainfo_key", "metainfo_value") values ('version', '${ambariSchemaVersion}'); diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql index 6044262..2ef9ed6 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -586,9 +586,42 @@ CREATE TABLE blueprint ( blueprint_name VARCHAR(255) NOT NULL, security_type VARCHAR(32) NOT NULL DEFAULT 'NONE', security_descriptor_reference VARCHAR(255), - stack_id BIGINT NOT NULL, - CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name), - CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id)); + CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name)); + +CREATE TABLE blueprint_mpack_instance( + id BIGINT NOT NULL, + blueprint_name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255) NOT NULL, + mpack_version VARCHAR(255) NOT NULL, + mpack_uri VARCHAR(255) NOT NULL, + mpack_id BIGINT, + CONSTRAINT PK_blueprint_mpack_inst PRIMARY KEY (id), + CONSTRAINT FK_mpi_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name), + CONSTRAINT FK_mpi_mpack_id FOREIGN KEY (mpack_id) REFERENCES mpacks(id)); + +CREATE TABLE blueprint_service ( + id BIGINT NOT NULL, + mpack_ref_id BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + CONSTRAINT PK_blueprint_service PRIMARY KEY (id), + CONSTRAINT FK_blueprint_service_mpack_ref FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference(id)); + +CREATE TABLE blueprint_service_config ( + service_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data TEXT NOT NULL, + config_attributes TEXT, + CONSTRAINT PK_bp_svc_conf PRIMARY KEY (service_id, type_name), + CONSTRAINT FK_bp_svc_config_to_service FOREIGN KEY (service_id) REFERENCES blueprint_service (id)); + +CREATE TABLE blueprint_mpack_configuration ( + mpack_ref_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data TEXT NOT NULL, + config_attributes TEXT, + CONSTRAINT PK_bp_mpack_conf PRIMARY KEY (mpack_ref_id, type_name), + CONSTRAINT FK_bp_mpack_config_to_mpack FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference (id)); CREATE TABLE hostgroup ( blueprint_name VARCHAR(255) NOT NULL, @@ -598,11 +631,15 @@ CREATE TABLE hostgroup ( CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name)); CREATE TABLE hostgroup_component ( + id BIGINT NOT NULL, blueprint_name VARCHAR(255) NOT NULL, hostgroup_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255), + mpack_version VARCHAR(100), + service_name VARCHAR(255), provision_action VARCHAR(255), - CONSTRAINT PK_hostgroup_component PRIMARY KEY (blueprint_name, hostgroup_name, name), + CONSTRAINT PK_hostgroup_component PRIMARY KEY (id), CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name)); CREATE TABLE blueprint_configuration ( @@ -1223,7 +1260,10 @@ INSERT INTO ambari_sequences (sequence_name, sequence_value) VALUES ('remote_cluster_id_seq', 0), ('remote_cluster_service_id_seq', 0), ('servicecomponent_version_id_seq', 0), - ('hostcomponentdesiredstate_id_seq', 0); + ('hostcomponentdesiredstate_id_seq', 0), + ('blueprint_service_id_seq', 0), + ('blueprint_mpack_instance_id_seq', 0), + ('hostgroup_component_id_seq', 0); INSERT INTO adminresourcetype (resource_type_id, resource_type_name) VALUES (1, 'AMBARI'), diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql index b9a4f0e..36ef59f 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql @@ -95,25 +95,6 @@ CREATE TABLE configuration_base ( CONSTRAINT PK_configuration_base PRIMARY KEY (id) ); -CREATE TABLE clusterconfig ( - config_id NUMERIC(19) NOT NULL, - version_tag VARCHAR(255) NOT NULL, - version NUMERIC(19) NOT NULL, - type_name VARCHAR(255) NOT NULL, - cluster_id NUMERIC(19) NOT NULL, - stack_id NUMERIC(19) NOT NULL, - selected SMALLINT NOT NULL DEFAULT 0, - config_data TEXT NOT NULL, - config_attributes TEXT, - create_timestamp NUMERIC(19) NOT NULL, - unmapped SMALLINT NOT NULL DEFAULT 0, - selected_timestamp NUMERIC(19) NOT NULL DEFAULT 0, - CONSTRAINT PK_clusterconfig PRIMARY KEY (config_id), - CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), - CONSTRAINT FK_clusterconfig_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id), - CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag), - CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version)); - CREATE TABLE ambari_configuration ( category_name VARCHAR(100) NOT NULL, property_name VARCHAR(100) NOT NULL, @@ -610,11 +591,44 @@ CREATE TABLE requestschedulebatchrequest ( CREATE TABLE blueprint ( blueprint_name VARCHAR(255) NOT NULL, - stack_id NUMERIC(19) NOT NULL, security_type VARCHAR(32) NOT NULL DEFAULT 'NONE', security_descriptor_reference VARCHAR(255), - CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name), - CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id)); + CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name)); + +CREATE TABLE blueprint_mpack_instance( + id NUMERIC(19) NOT NULL, + blueprint_name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255) NOT NULL, + mpack_version VARCHAR(255) NOT NULL, + mpack_uri VARCHAR(255) NOT NULL, + mpack_id NUMERIC(19), + CONSTRAINT PK_blueprint_mpack_inst PRIMARY KEY (id), + CONSTRAINT FK_mpi_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name), + CONSTRAINT FK_mpi_mpack_id FOREIGN KEY (mpack_id) REFERENCES mpacks(id)); + +CREATE TABLE blueprint_service ( + id NUMERIC(19) NOT NULL, + mpack_ref_id BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + CONSTRAINT PK_blueprint_service PRIMARY KEY (id), + CONSTRAINT FK_blueprint_service_mpack_ref FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference(id)); + +CREATE TABLE blueprint_service_config ( + service_id NUMERIC(19) NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data TEXT NOT NULL, + config_attributes TEXT, + CONSTRAINT PK_bp_svc_conf PRIMARY KEY (service_id, type_name), + CONSTRAINT FK_bp_svc_config_to_service FOREIGN KEY (service_id) REFERENCES blueprint_service (id)); + +CREATE TABLE blueprint_mpack_configuration ( + mpack_ref_id NUMERIC(19) NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data TEXT NOT NULL, + config_attributes TEXT, + CONSTRAINT PK_bp_mpack_conf PRIMARY KEY (mpack_ref_id, type_name), + CONSTRAINT FK_bp_mpack_config_to_mpack FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference (id)); CREATE TABLE hostgroup ( blueprint_name VARCHAR(255) NOT NULL, @@ -624,12 +638,16 @@ CREATE TABLE hostgroup ( CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name)); CREATE TABLE hostgroup_component ( + id NUMERIC(19) NOT NULL, blueprint_name VARCHAR(255) NOT NULL, hostgroup_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255), + mpack_version VARCHAR(100), + service_name VARCHAR(255), provision_action VARCHAR(255), - CONSTRAINT PK_hostgroup_component PRIMARY KEY (blueprint_name, hostgroup_name, name), - CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup(blueprint_name, name)); + CONSTRAINT PK_hostgroup_component PRIMARY KEY (id), + CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name)); CREATE TABLE blueprint_configuration ( blueprint_name VARCHAR(255) NOT NULL, @@ -1250,6 +1268,9 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_clus INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('remote_cluster_service_id_seq', 0); INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('servicecomponent_version_id_seq', 0); INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostcomponentdesiredstate_id_seq', 0); +INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('blueprint_service_id_seq', 0); +INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('blueprint_mpack_instance_id_seq', 0); +INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostgroup_component_id_seq', 0); insert into adminresourcetype (resource_type_id, resource_type_name) select 1, 'AMBARI' diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql index fe9e987..43ef059 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -109,25 +109,6 @@ CREATE TABLE configuration_base ( CONSTRAINT PK_configuration_base PRIMARY KEY (id) ); -CREATE TABLE clusterconfig ( - config_id BIGINT NOT NULL, - version_tag VARCHAR(255) NOT NULL, - version BIGINT NOT NULL, - type_name VARCHAR(255) NOT NULL, - cluster_id BIGINT NOT NULL, - stack_id BIGINT NOT NULL, - selected SMALLINT NOT NULL DEFAULT 0, - config_data VARCHAR(MAX) NOT NULL, - config_attributes VARCHAR(MAX), - create_timestamp BIGINT NOT NULL, - unmapped SMALLINT NOT NULL DEFAULT 0, - selected_timestamp BIGINT NOT NULL DEFAULT 0, - CONSTRAINT PK_clusterconfig PRIMARY KEY CLUSTERED (config_id), - CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), - CONSTRAINT FK_clusterconfig_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id), - CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag), - CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version)); - CREATE TABLE ambari_configuration ( category_name VARCHAR(100) NOT NULL, property_name VARCHAR(100) NOT NULL, @@ -310,9 +291,9 @@ CREATE TABLE hostcomponentdesiredstate ( maintenance_state VARCHAR(32) NOT NULL, restart_required BIT NOT NULL DEFAULT 0, CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY CLUSTERED (id), - CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_name, host_id, cluster_id), + CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_id, host_id, cluster_id), CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), - CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_name, cluster_id)); + CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, cluster_id)); CREATE TABLE hostcomponentstate ( id BIGINT NOT NULL, @@ -619,11 +600,44 @@ CREATE TABLE requestschedulebatchrequest ( CREATE TABLE blueprint ( blueprint_name VARCHAR(255) NOT NULL, - stack_id BIGINT NOT NULL, security_type VARCHAR(32) NOT NULL DEFAULT 'NONE', security_descriptor_reference VARCHAR(255), - CONSTRAINT PK_blueprint PRIMARY KEY CLUSTERED (blueprint_name), - CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES stack(stack_id)); + CONSTRAINT PK_blueprint PRIMARY KEY CLUSTERED (blueprint_name)); + +CREATE TABLE blueprint_mpack_instance( + id BIGINT NOT NULL, + blueprint_name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255) NOT NULL, + mpack_version VARCHAR(255) NOT NULL, + mpack_uri VARCHAR(255) NOT NULL, + mpack_id BIGINT, + CONSTRAINT PK_blueprint_mpack_inst PRIMARY KEY (id), + CONSTRAINT FK_mpi_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name), + CONSTRAINT FK_mpi_mpack_id FOREIGN KEY (mpack_id) REFERENCES mpacks(id)); + +CREATE TABLE blueprint_service ( + id BIGINT NOT NULL, + mpack_ref_id BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + CONSTRAINT PK_blueprint_service PRIMARY KEY (id), + CONSTRAINT FK_blueprint_service_mpack_ref FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference(id)); + +CREATE TABLE blueprint_service_config ( + service_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data TEXT NOT NULL, + config_attributes TEXT, + CONSTRAINT PK_bp_svc_conf PRIMARY KEY (service_id, type_name), + CONSTRAINT FK_bp_svc_config_to_service FOREIGN KEY (service_id) REFERENCES blueprint_service (id)); + +CREATE TABLE blueprint_mpack_configuration ( + mpack_ref_id BIGINT NOT NULL, + type_name VARCHAR(255) NOT NULL, + config_data TEXT NOT NULL, + config_attributes TEXT, + CONSTRAINT PK_bp_mpack_conf PRIMARY KEY (mpack_ref_id, type_name), + CONSTRAINT FK_bp_mpack_config_to_mpack FOREIGN KEY (mpack_ref_id) REFERENCES blueprint_mpack_reference (id)); CREATE TABLE hostgroup ( blueprint_name VARCHAR(255) NOT NULL, @@ -633,13 +647,18 @@ CREATE TABLE hostgroup ( CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name)); CREATE TABLE hostgroup_component ( + id BIGINT NOT NULL, blueprint_name VARCHAR(255) NOT NULL, hostgroup_name VARCHAR(255) NOT NULL, - NAME VARCHAR(255) NOT NULL, + name VARCHAR(255) NOT NULL, + mpack_name VARCHAR(255), + mpack_version VARCHAR(100), + service_name VARCHAR(255), provision_action VARCHAR(255), - CONSTRAINT PK_hostgroup_component PRIMARY KEY CLUSTERED (blueprint_name, hostgroup_name, NAME), + CONSTRAINT PK_hostgroup_component PRIMARY KEY CLUSTERED (id), CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name)); + CREATE TABLE blueprint_configuration ( blueprint_name VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, @@ -1276,7 +1295,10 @@ BEGIN TRANSACTION ('remote_cluster_id_seq', 0), ('remote_cluster_service_id_seq', 0), ('servicecomponent_version_id_seq', 0), - ('hostcomponentdesiredstate_id_seq', 0); + ('hostcomponentdesiredstate_id_seq', 0), + ('blueprint_service_id_seq', 0), + ('blueprint_mpack_instance_id_seq', 0), + ('hostgroup_component_id_seq', 0); insert into adminresourcetype (resource_type_id, resource_type_name) values diff --git a/ambari-server/src/main/resources/META-INF/persistence.xml b/ambari-server/src/main/resources/META-INF/persistence.xml index 9c99341..6f930b1 100644 --- a/ambari-server/src/main/resources/META-INF/persistence.xml +++ b/ambari-server/src/main/resources/META-INF/persistence.xml @@ -23,6 +23,10 @@ <class>org.apache.ambari.server.orm.entities.BlueprintConfigEntity</class> <class>org.apache.ambari.server.orm.entities.BlueprintSettingEntity</class> <class>org.apache.ambari.server.orm.entities.BlueprintEntity</class> + <class>org.apache.ambari.server.orm.entities.BlueprintMpackInstanceEntity</class> + <class>org.apache.ambari.server.orm.entities.BlueprintMpackConfigEntity</class> + <class>org.apache.ambari.server.orm.entities.BlueprintServiceEntity</class> + <class>org.apache.ambari.server.orm.entities.BlueprintServiceConfigEntity</class> <class>org.apache.ambari.server.orm.entities.ClusterConfigEntity</class> <class>org.apache.ambari.server.orm.entities.ClusterEntity</class> <class>org.apache.ambari.server.orm.entities.ServiceGroupEntity</class> diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java index c7b8d71..6f81ce5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java @@ -19,7 +19,6 @@ package org.apache.ambari.server.controller.internal; import static org.easymock.EasyMock.anyBoolean; -import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.createStrictMock; @@ -62,14 +61,13 @@ import org.apache.ambari.server.controller.spi.ResourceProvider; import org.apache.ambari.server.controller.spi.SystemException; import org.apache.ambari.server.controller.spi.UnsupportedPropertyException; import org.apache.ambari.server.orm.dao.BlueprintDAO; -import org.apache.ambari.server.orm.dao.StackDAO; import org.apache.ambari.server.orm.entities.BlueprintConfigEntity; import org.apache.ambari.server.orm.entities.BlueprintConfiguration; import org.apache.ambari.server.orm.entities.BlueprintEntity; +import org.apache.ambari.server.orm.entities.BlueprintMpackInstanceEntity; import org.apache.ambari.server.orm.entities.BlueprintSettingEntity; import org.apache.ambari.server.orm.entities.HostGroupComponentEntity; import org.apache.ambari.server.orm.entities.HostGroupEntity; -import org.apache.ambari.server.orm.entities.StackEntity; import org.apache.ambari.server.state.PropertyInfo; import org.apache.ambari.server.state.SecurityType; import org.apache.ambari.server.state.StackInfo; @@ -101,7 +99,6 @@ public class BlueprintResourceProviderTest { public ExpectedException expectedException = ExpectedException.none(); private final static BlueprintDAO dao = createStrictMock(BlueprintDAO.class); - private final static StackDAO stackDAO = createNiceMock(StackDAO.class); private final static BlueprintEntity entity = createStrictMock(BlueprintEntity.class); private final static Blueprint blueprint = createMock(Blueprint.class); private final static AmbariMetaInfo metaInfo = createMock(AmbariMetaInfo.class); @@ -113,16 +110,6 @@ public class BlueprintResourceProviderTest { @BeforeClass public static void initClass() { BlueprintResourceProvider.init(blueprintFactory, dao, securityFactory, gson, metaInfo); - - StackEntity stackEntity = new StackEntity(); - stackEntity.setStackName("test-stack-name"); - stackEntity.setStackVersion("test-stack-version"); - - expect( - stackDAO.find(anyObject(String.class), - anyObject(String.class))).andReturn(stackEntity).anyTimes(); - replay(stackDAO); - } private Map<String, Set<HashMap<String, String>>> getSettingProperties() { @@ -750,8 +737,6 @@ public class BlueprintResourceProviderTest { private void validateResource(Resource resource, boolean containsConfig) { assertEquals(BLUEPRINT_NAME, resource.getPropertyValue(BlueprintResourceProvider.BLUEPRINT_NAME_PROPERTY_ID)); - assertEquals("test-stack-name", resource.getPropertyValue(BlueprintResourceProvider.STACK_NAME_PROPERTY_ID)); - assertEquals("test-stack-version", resource.getPropertyValue(BlueprintResourceProvider.STACK_VERSION_PROPERTY_ID)); Collection<Map<String, Object>> hostGroupProperties = (Collection<Map<String, Object>>) resource.getPropertyValue(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID); @@ -820,11 +805,13 @@ public class BlueprintResourceProviderTest { String stackName = (String) properties.get(BlueprintResourceProvider.STACK_NAME_PROPERTY_ID); String stackVersion = (String) properties.get(BlueprintResourceProvider.STACK_VERSION_PROPERTY_ID); - StackEntity stackEntity = new StackEntity(); - stackEntity.setStackName(stackName); - stackEntity.setStackVersion(stackVersion); - entity.setStack(stackEntity); + BlueprintMpackInstanceEntity mpackEntity = new BlueprintMpackInstanceEntity(); + mpackEntity.setMpackName(stackName); + mpackEntity.setMpackVersion(stackVersion); + mpackEntity.setBlueprint(entity); + + entity.getMpackReferences().add(mpackEntity); Set<Map<String, Object>> hostGroupProperties = (Set<Map<String, Object>>) properties.get( BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID); @@ -1023,11 +1010,7 @@ public class BlueprintResourceProviderTest { @Test public void testPopulateConfigurationList() throws Exception { - StackEntity stackEntity = new StackEntity(); - stackEntity.setStackName("test-stack-name"); - stackEntity.setStackVersion("test-stack-version"); BlueprintEntity entity = createMock(BlueprintEntity.class); - expect(entity.getStack()).andReturn(stackEntity).anyTimes(); HashMap<PropertyInfo.PropertyType, Set<String>> pwdProperties = new HashMap<PropertyInfo.PropertyType, Set<String>>() {{ put(PropertyInfo.PropertyType.PASSWORD, new HashSet<String>(){{ @@ -1041,7 +1024,12 @@ public class BlueprintResourceProviderTest { expect(info.getConfigPropertiesTypes("type3")).andReturn(pwdProperties).anyTimes(); expect(metaInfo.getStack("test-stack-name", "test-stack-version")).andReturn(info).anyTimes(); - replay(info, metaInfo, entity); + BlueprintMpackInstanceEntity mpackReference = createMock(BlueprintMpackInstanceEntity.class); + expect(mpackReference.getMpackName()).andReturn("test-stack-name").anyTimes(); + expect(mpackReference.getMpackVersion()).andReturn("test-stack-version").anyTimes(); + expect(entity.getMpackReferences()).andReturn(Collections.singleton(mpackReference)).anyTimes(); + + replay(info, metaInfo, entity, mpackReference); // attributes is null @@ -1124,11 +1112,7 @@ public class BlueprintResourceProviderTest { @Test public void testPopulateSettingList() throws Exception { - StackEntity stackEntity = new StackEntity(); - stackEntity.setStackName("test-stack-name"); - stackEntity.setStackVersion("test-stack-version"); BlueprintEntity entity = createMock(BlueprintEntity.class); - expect(entity.getStack()).andReturn(stackEntity).anyTimes(); HashMap<PropertyInfo.PropertyType, Set<String>> pwdProperties = new HashMap<PropertyInfo.PropertyType, Set<String>>() {{ put(PropertyInfo.PropertyType.PASSWORD, new HashSet<String>(){{ diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/db/DDLTests.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/db/DDLTests.java index 099400b..eda0c70 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/db/DDLTests.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/db/DDLTests.java @@ -75,6 +75,7 @@ public class DDLTests { verifyDDL("SQLServer"); } + /** * To verify if DDL have certain characteristics: * <ul> @@ -88,35 +89,47 @@ public class DDLTests { LOG.info("Checking DDL for {}", dbType); DDL ddl = DDLTestUtils.getDdl(dbType); printDDLMetrics(ddl); + List<String> issues = new ArrayList<>(); // check for unwanted alter tables - Assert.assertEquals("Expected count of alter tables mismatch. Please include all constraint definitions in " + - "the create table statement, only use alter table in exceptional cases, such as to work around a circular " + - "FK dependency. Would another such case occur, please document it in the DDL's and adjust the " + - "EXPECTED_ALTER_TABLE_COUNT in this test.", - EXPECTED_ALTER_TABLE_COUNT, - ddl.alterTables.size()); + if (ddl.alterTables.size() != EXPECTED_ALTER_TABLE_COUNT) { + issues.add(String.format( + "Expected count of alter tables mismatch (%d vd %d). Please include all constraint definitions in " + + "the create table statement, only use alter table in exceptional cases, such as to work around a circular " + + "FK dependency. Would another such case occur, please document it in the DDL's and adjust the " + + "EXPECTED_ALTER_TABLE_COUNT in this test.", ddl.alterTables.size(), EXPECTED_ALTER_TABLE_COUNT)); + } // check for too long table/constraint names for (String tableName: ddl.tableNames()) { - Assert.assertTrue("Table name exceeds the 30 character limit: " + tableName, tableName.length() <= 30); + if (tableName.length() > 30) { + issues.add("Table name exceeds the 30 character limit: " + tableName); + } } for (Table table: ddl.tables.values()) { - Assert.assertTrue("PK name exceeds the 30 character limit: " + table.primaryKey, - !table.primaryKey.isPresent() || table.primaryKey.get().name().length() <= 30); + if (table.primaryKey.isPresent() && table.primaryKey.get().name().length() > 30) { + issues.add("PK name exceeds the 30 character limit: " + table.primaryKey.get()); + } for (Constraint constr: Sets.union(table.foreignKeys, table.uniqueConstraints)) { - Assert.assertTrue("Constraint name exceeds the 30 character limit: " + constr, constr.name().length() <= 30); + if (constr.name().length() > 30) { + issues.add(String.format("Constraint name on table [%s] exceeds the 30 character limit: %s", + table.name, constr.name())); + } } } // check for unnamed PK's (skip quartz tables) for (Table table: ddl.tables.values()) { - Assert.assertFalse("Unnamed PK exists for table: " + table.name, - !table.name.startsWith("qrtz") && table.primaryKey.isPresent() && table.primaryKey.get().name().equals("<default>")); - for (Constraint constr: Sets.union(table.foreignKeys, table.uniqueConstraints)) { - Assert.assertTrue("Constraint name exceeds the 30 character limit: " + constr, constr.name().length() <= 30); + if (!table.name.startsWith("qrtz") && + table.primaryKey.isPresent() && + table.primaryKey.get().name().equals("<default>")) { + issues.add("Unnamed PK exists for table: " + table.name); } } - + if (!issues.isEmpty()) { + String message = "There were " + issues.size() + " issues found:\n- " + + Joiner.on("\n- ").join(issues); + Assert.fail(message); + } } @Test diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/BlueprintEntityTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/BlueprintEntityTest.java index 1b0b996..a9f6172 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/BlueprintEntityTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/BlueprintEntityTest.java @@ -50,13 +50,6 @@ public class BlueprintEntityTest { } @Test - public void testSetGetStack() { - BlueprintEntity entity = new BlueprintEntity(); - entity.setStack(stackEntity); - assertEquals(stackEntity, entity.getStack()); - } - - @Test public void testSetGetHostGroups() { BlueprintEntity entity = new BlueprintEntity(); Collection<HostGroupEntity> hostGroups = Collections.emptyList(); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/BlueprintEntityTest2.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/BlueprintEntityTest2.java new file mode 100644 index 0000000..6d0a5e2 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/BlueprintEntityTest2.java @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.orm.entities; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import java.sql.SQLException; +import java.util.Collection; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.H2DatabaseCleaner; +import org.apache.ambari.server.api.services.AmbariMetaInfo; +import org.apache.ambari.server.controller.internal.ProvisionAction; +import org.apache.ambari.server.orm.GuiceJpaInitializer; +import org.apache.ambari.server.orm.InMemoryDefaultTestModule; +import org.apache.ambari.server.orm.dao.BlueprintDAO; +import org.apache.ambari.server.orm.dao.StackDAO; +import org.apache.ambari.server.state.SecurityType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; + +/** + * Test saving and loading a blueprint with all associated entities. + */ +public class BlueprintEntityTest2 { + + public static final String BLUEPRINT_NAME = "test-blueprint"; + @Inject + private Injector injector; + @Inject + private StackDAO stackDAO; + @Inject + private BlueprintDAO blueprintDAO; + + + @Before + public void setup() { + injector = Guice.createInjector(new InMemoryDefaultTestModule()); + injector.getInstance(GuiceJpaInitializer.class); + injector.injectMembers(this); + injector.getInstance(AmbariMetaInfo.class); + } + + @After + public void teardown() throws AmbariException, SQLException { + H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector); + } + + /** + * Test loading and saving a blueprint without stack defined (Ambari 3.0 blueprints normally define mpacks, not stacks) + */ + @Test + public void testCreateAndLoadBlueprint() { + blueprintDAO.create(createTestBlueprint()); + verifyBlueprint(blueprintDAO.findByName(BLUEPRINT_NAME)); + } + + private void verifyBlueprint(BlueprintEntity blueprintEntity) { + assertEquals(1, blueprintEntity.getMpackReferences().size()); + + BlueprintMpackInstanceEntity mpackReferenceEntity = + blueprintEntity.getMpackReferences().iterator().next(); + assertEquals("HDPCORE", mpackReferenceEntity.getMpackName()); + assertEquals(1, mpackReferenceEntity.getConfigurations().size()); + + BlueprintMpackConfigEntity mpackConfigEntity = + mpackReferenceEntity.getConfigurations().iterator().next(); + assertEquals("configdata", mpackConfigEntity.getConfigData()); + assertEquals("zk-env.sh", mpackConfigEntity.getType()); + + assertEquals(1, blueprintEntity.getHostGroups().size()); + HostGroupEntity hostGroup = blueprintEntity.getHostGroups().iterator().next(); + + Collection<HostGroupComponentEntity> hgComponents = hostGroup.getComponents(); + Map<String, HostGroupComponentEntity> hgComponentMap = + hgComponents.stream().collect(Collectors.toMap(HostGroupComponentEntity::getName, Function.identity())); + assertEquals(ImmutableSet.of("ZOOKEEPER_CLIENT", "HDFS_CLIENT"), hgComponentMap.keySet()); + assertEquals(ProvisionAction.INSTALL_ONLY.name(), hgComponentMap.get("HDFS_CLIENT").getProvisionAction()); + assertEquals("HDPCORE", hgComponentMap.get("ZOOKEEPER_CLIENT").getMpackName()); + assertEquals("ZK1", hgComponentMap.get("ZOOKEEPER_CLIENT").getServiceName()); + + assertEquals(1, hostGroup.getConfigurations().size()); + HostGroupConfigEntity hostGroupConfig = hostGroup.getConfigurations().iterator().next(); + assertEquals("hdfs-site", hostGroupConfig.getType()); + + assertEquals(1, mpackReferenceEntity.getServiceInstances().size()); + BlueprintServiceEntity service = mpackReferenceEntity.getServiceInstances().iterator().next(); + assertEquals("ZK1", service.getName()); + assertEquals("ZOOKEEPER", service.getType()); + assertSame(mpackReferenceEntity, service.getMpackReference()); + + assertEquals(1, service.getConfigurations().size()); + assertEquals("hadoop-env", service.getConfigurations().iterator().next().getType()); + } + + private BlueprintEntity createTestBlueprint() { + BlueprintEntity blueprintEntity = new BlueprintEntity(); + blueprintEntity.setBlueprintName(BLUEPRINT_NAME); + blueprintEntity.setSecurityType(SecurityType.NONE); + + BlueprintMpackInstanceEntity mpackReferenceEntity = new BlueprintMpackInstanceEntity(); + mpackReferenceEntity.setBlueprint(blueprintEntity); + mpackReferenceEntity.setMpackName("HDPCORE"); + mpackReferenceEntity.setMpackVersion("3.0.0.0"); + mpackReferenceEntity.setMpackUri("http://hdpcore.org/3.0.0.0"); + + BlueprintMpackConfigEntity mpackConfigEntity = new BlueprintMpackConfigEntity(); + mpackConfigEntity.setMpackReference(mpackReferenceEntity); + mpackConfigEntity.setConfigAttributes("attributes"); + mpackConfigEntity.setConfigData("configdata"); + mpackConfigEntity.setType("zk-env.sh"); + mpackReferenceEntity.getConfigurations().add(mpackConfigEntity); + + HostGroupEntity hostGroupEntity = new HostGroupEntity(); + hostGroupEntity.setBlueprintEntity(blueprintEntity); + hostGroupEntity.setName("hostgroup1"); + + HostGroupConfigEntity hgConfigEntity = new HostGroupConfigEntity(); + hgConfigEntity.setHostGroupEntity(hostGroupEntity); + hgConfigEntity.setType("hdfs-site"); + hgConfigEntity.setConfigAttributes("attributes"); + hgConfigEntity.setConfigData("data"); + hostGroupEntity.getConfigurations().add(hgConfigEntity); + + HostGroupComponentEntity hgComponentEntity1 = new HostGroupComponentEntity(); + hgComponentEntity1.setHostGroupEntity(hostGroupEntity); + hgComponentEntity1.setName("HDFS_CLIENT"); + hgComponentEntity1.setProvisionAction(ProvisionAction.INSTALL_ONLY.name()); + hostGroupEntity.addComponent(hgComponentEntity1); + + HostGroupComponentEntity hgComponentEntity2 = new HostGroupComponentEntity(); + hgComponentEntity2.setHostGroupEntity(hostGroupEntity); + hgComponentEntity2.setName("ZOOKEEPER_CLIENT"); + hgComponentEntity2.setMpackName("HDPCORE"); + hgComponentEntity2.setMpackVersion("3.0.0.0"); + hgComponentEntity2.setServiceName("ZK1"); + hostGroupEntity.addComponent(hgComponentEntity2); + + BlueprintServiceEntity blueprintService = new BlueprintServiceEntity(); + blueprintService.setMpackReference(mpackReferenceEntity); + blueprintService.setName("ZK1"); + blueprintService.setType("ZOOKEEPER"); + mpackReferenceEntity.getServiceInstances().add(blueprintService); + + BlueprintServiceConfigEntity blueprintServiceConfigEntity = new BlueprintServiceConfigEntity(); + blueprintServiceConfigEntity.setService(blueprintService); + blueprintServiceConfigEntity.setType("hadoop-env"); + blueprintServiceConfigEntity.setConfigAttributes("attributes"); + blueprintServiceConfigEntity.setConfigData("data"); + blueprintService.getConfigurations().add(blueprintServiceConfigEntity); + + blueprintEntity.getMpackReferences().add(mpackReferenceEntity); + blueprintEntity.getHostGroups().add(hostGroupEntity); + + return blueprintEntity; + } +} \ No newline at end of file -- To stop receiving notification emails like this one, please contact beny...@apache.org.