Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMBARI-26309: Ambari server takes up about an hour to start #3950

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion ambari-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<slf4j.version>2.0.0</slf4j.version>
<reload4j.version>1.2.22</reload4j.version>
<logback.version>1.5.16</logback.version>
<guice.version>5.1.0</guice.version>
<guice.version>7.0.0</guice.version>
<spring.version>5.3.22</spring.version>
<spring.security.version>5.7.8</spring.security.version>
<fasterxml.jackson.version>2.18.2</fasterxml.jackson.version>
Expand Down
3 changes: 2 additions & 1 deletion ambari-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -1239,6 +1239,7 @@
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-persist</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.ambari.server.orm.AmbariJpaLocalTxnInterceptor;
Expand All @@ -47,6 +44,9 @@
import com.google.inject.persist.finder.DynamicFinder;
import com.google.inject.persist.finder.Finder;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;

/**
* Copy of guice persist module for local modifications
*/
Expand All @@ -61,6 +61,7 @@ public AmbariJpaPersistModule(String jpaUnit) {
}
}

private JpaPersistOptions options;
private Map<?, ?> properties;
private MethodInterceptor transactionInterceptor;

Expand Down Expand Up @@ -99,13 +100,18 @@ public AmbariJpaPersistModule(String jpaUnit) {
return properties;
}

@Provides @Jpa JpaPersistOptions provideOptions() {
return options;
}

/**
* Configures the JPA persistence provider with a set of properties.
*
* @param properties A set of name value pairs that configure a JPA persistence
* provider as per the specification.
*/
public AmbariJpaPersistModule properties(Map<?, ?> properties) {
this.options = JpaPersistOptions.builder().setAutoBeginWorkOnEntityManagerCreation(true).build();
this.properties = properties;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class AmbariJpaPersistService extends JpaPersistService {
private final AtomicBoolean jpaStarted = new AtomicBoolean(false);

@Inject
public AmbariJpaPersistService(@Jpa String persistenceUnitName, @Jpa Map<?, ?> persistenceProperties) {
super(persistenceUnitName, persistenceProperties);
public AmbariJpaPersistService(@Jpa JpaPersistOptions options, @Jpa String persistenceUnitName, @Jpa Map<?, ?> persistenceProperties) {
super(options, persistenceUnitName, persistenceProperties);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.persistence.EntityManager;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ClusterNotFoundException;
import org.apache.ambari.server.Role;
Expand Down Expand Up @@ -91,6 +89,7 @@
import com.google.inject.name.Named;
import com.google.inject.persist.UnitOfWork;

import jakarta.persistence.EntityManager;

/**
* This class encapsulates the action scheduler thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;

import javax.inject.Named;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.HostNotFoundException;
import org.apache.ambari.server.actionmanager.ActionManager;
Expand Down Expand Up @@ -61,6 +59,7 @@
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;
import com.google.inject.name.Named;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

import java.util.Objects;

import javax.inject.Inject;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.agent.stomp.dto.Hashable;
import org.apache.ambari.server.events.STOMPEvent;
import org.apache.ambari.server.events.publishers.STOMPUpdatePublisher;

import com.google.inject.Inject;

/**
* Is used to saving and updating last version of event in cluster scope
* @param <T> event with hash to control version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import javax.inject.Inject;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.AmbariRuntimeException;
import org.apache.ambari.server.agent.stomp.dto.Hashable;
Expand All @@ -33,6 +31,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;

/**
* Is used to saving and updating last version of event in host scope
* @param <T> event with hash to control version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
import java.util.Map;
import java.util.TreeMap;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.AmbariRuntimeException;
import org.apache.ambari.server.agent.stomp.dto.AlertCluster;
Expand All @@ -51,6 +47,9 @@

import com.google.common.collect.Sets;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

@Singleton
public class AlertDefinitionsHolder extends AgentHostDataHolder<AlertDefinitionsAgentUpdateEvent> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute;

import org.apache.ambari.server.controller.predicate.AlwaysPredicate;
import org.apache.ambari.server.controller.predicate.ArrayPredicate;
import org.apache.ambari.server.controller.predicate.CategoryPredicate;
Expand All @@ -37,9 +30,16 @@
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.utilities.PredicateHelper;

import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.metamodel.SingularAttribute;

/**
* The {@link JpaPredicateVisitor} is used to convert an Ambari
* {@link Predicate} into a JPA {@link javax.persistence.criteria.Predicate}.
* {@link Predicate} into a JPA {@link jakarta.persistence.criteria.Predicate}.
*/
public abstract class JpaPredicateVisitor<T> implements PredicateVisitor {
/**
Expand All @@ -65,15 +65,15 @@ public abstract class JpaPredicateVisitor<T> implements PredicateVisitor {
/**
* The last calculated predicate.
*/
private javax.persistence.criteria.Predicate m_lastPredicate = null;
private jakarta.persistence.criteria.Predicate m_lastPredicate = null;

/**
* A queue of lists of {@link javax.persistence.criteria.Predicate}. Every
* A queue of lists of {@link jakarta.persistence.criteria.Predicate}. Every
* time an {@code OR} or {@code AND} is encountered, a new chain (list) is
* created and the prior list is enqeued. When the logical statement is
* closed, the chain is completed and added to the prior chain's list.
*/
private ArrayDeque<List<javax.persistence.criteria.Predicate>> m_queue =
private ArrayDeque<List<jakarta.persistence.criteria.Predicate>> m_queue =
new ArrayDeque<>();

/**
Expand Down Expand Up @@ -111,12 +111,12 @@ public JpaPredicateVisitor(EntityManager entityManager, Class<T> entityClass) {
String propertyId);

/**
* Gets the final JPA {@link javax.persistence.criteria.Predicate} after the
* Gets the final JPA {@link jakarta.persistence.criteria.Predicate} after the
* visitor is done traversing the Ambari {@link Predicate}.
*
* @return the predicate, or {@code null} if none.
*/
public javax.persistence.criteria.Predicate getJpaPredicate() {
public jakarta.persistence.criteria.Predicate getJpaPredicate() {
return m_lastPredicate;
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public void acceptComparisonPredicate(ComparisonPredicate predicate) {
}
}

javax.persistence.criteria.Predicate jpaPredicate = null;
jakarta.persistence.criteria.Predicate jpaPredicate = null;
if ("=".equals(operator)) {
jpaPredicate = m_builder.equal(path, value);
} else if ("<".equals(operator)) {
Expand Down Expand Up @@ -219,19 +219,19 @@ public void acceptArrayPredicate(ArrayPredicate predicate) {
}

// create a new list for all of the predicates in this chain
List<javax.persistence.criteria.Predicate> predicateList = new ArrayList<>();
List<jakarta.persistence.criteria.Predicate> predicateList = new ArrayList<>();
m_queue.add(predicateList);

// visit every child predicate so it can be added to the list
String operator = predicate.getOperator();
for (int i = 0; i < predicates.length; i++) {
PredicateHelper.visit(predicates[i], this);
}
javax.persistence.criteria.Predicate jpaPredicate = null;
jakarta.persistence.criteria.Predicate jpaPredicate = null;
// the list is done; deque and apply logical AND or OR
predicateList = m_queue.pollLast();
if (predicateList != null) {
javax.persistence.criteria.Predicate[] array = new javax.persistence.criteria.Predicate[predicateList.size()];
jakarta.persistence.criteria.Predicate[] array = new jakarta.persistence.criteria.Predicate[predicateList.size()];
array = predicateList.toArray(array);

if ("AND".equals(operator)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
import java.util.List;
import java.util.Set;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute;

import org.apache.ambari.server.controller.spi.SortRequest;
import org.apache.ambari.server.controller.spi.SortRequestProperty;
import org.apache.commons.lang.ObjectUtils;

import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.metamodel.SingularAttribute;

/**
* The {@link JpaSortBuilder} class is used to convert and Ambari
* {@link SortRequest} and list of {@link SortRequestProperty} into a JPA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
import java.util.stream.Collectors;

import javax.annotation.Nullable;
import javax.inject.Provider;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
Expand Down Expand Up @@ -85,6 +81,11 @@
import com.google.inject.Injector;
import com.google.inject.persist.Transactional;

import jakarta.inject.Provider;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;

public class DatabaseConsistencyCheckHelper {

private static final Logger LOG = LoggerFactory.getLogger(DatabaseConsistencyCheckHelper.class);
Expand Down Expand Up @@ -616,6 +617,7 @@ static void fixClusterConfigsNotMappedToAnyService() {
* @return ClusterConfigs that are not mapped to Service
*/
private static List<ClusterConfigEntity> getNotMappedClusterConfigsToService() {
injector.getProvider(EntityManager.class);
Provider<EntityManager> entityManagerProvider = injector.getProvider(EntityManager.class);
EntityManager entityManager = entityManagerProvider.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

import java.util.Set;

import javax.inject.Inject;

import org.apache.ambari.server.orm.dao.Cleanable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -56,6 +53,10 @@
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.DelegatingFilterProxy;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

import javassist.util.proxy.ProxyFactory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import java.util.stream.Collectors;

import javax.annotation.Nullable;
import javax.persistence.RollbackException;

import org.apache.ambari.annotations.Experimental;
import org.apache.ambari.annotations.ExperimentalFeature;
Expand Down Expand Up @@ -275,6 +274,8 @@
import com.google.inject.Singleton;
import com.google.inject.persist.Transactional;

import jakarta.persistence.RollbackException;

@Singleton
public class AmbariManagementControllerImpl implements AmbariManagementController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.List;
import java.util.Map;

import javax.persistence.RollbackException;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.orm.dao.ExtensionDAO;
import org.apache.ambari.server.orm.dao.ExtensionLinkDAO;
Expand All @@ -44,6 +42,8 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;

import jakarta.persistence.RollbackException;

@Singleton
public class AmbariManagementHelper {

Expand Down
Loading